Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
nsanta committed Oct 17, 2013
0 parents commit f5e9917
Show file tree
Hide file tree
Showing 84 changed files with 2,762 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build/
/tags
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 2.6)
project(tpofinder)

# General settings
set(BUILD_SHARED_LIBS true)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
add_definitions(-std=c++0x)

# OpenCV
find_package(OpenCV 2.4 REQUIRED)

# Boost
find_package(Boost COMPONENTS filesystem program_options system)

# Sources and headers
file(GLOB srcs src/*.cpp)
file(GLOB tsts test/test*.cpp)
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_BINARY_DIR}/include")

# Configure headers
configure_file(
"${PROJECT_SOURCE_DIR}/include/tpofinder/configure.h.in"
"${PROJECT_BINARY_DIR}/include/tpofinder/configure.h")

# Library construction
add_library(${PROJECT_NAME} ${srcs})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

# Executables
add_executable(model_homography apps/model_homography.cpp)
add_executable(sequence_homography apps/sequence_homography.cpp)
add_executable(invert_homography apps/invert_homography.cpp)
add_executable(tpofind apps/tpofind.cpp)
target_link_libraries(model_homography ${PROJECT_NAME})
target_link_libraries(sequence_homography ${PROJECT_NAME})
target_link_libraries(invert_homography ${PROJECT_NAME})
target_link_libraries(tpofind ${PROJECT_NAME})

# Data
file(COPY "${PROJECT_SOURCE_DIR}/data" DESTINATION "${PROJECT_BINARY_DIR}")

# Testing
enable_testing()

# Set up gest; see also
# http://groups.google.com/group/googletestframework/browse_thread/thread/d1259032b859e5a3
# for a discussion on how to best integrate gtest with a project that uses
# cmake. Here, don't use FindGTest but rather ship gtest along with the source
# as a tar.gz which can be handled by cmake.
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xvzf ${PROJECT_SOURCE_DIR}/gtest-1.6.0.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

add_subdirectory(${CMAKE_BINARY_DIR}/gtest-1.6.0)
include_directories(${CMAKE_BINARY_DIR}/gtest-1.6.0/include)
set(GTest_LIBRARIES gtest)

add_executable(utest ${tsts})
target_link_libraries(utest ${GTest_LIBRARIES} ${PROJECT_NAME})
28 changes: 28 additions & 0 deletions LICENSE-GTEST.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright 2008, Google Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 changes: 20 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2012 Andreas Heider, Julius Adorf, Markus Grimm

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

43 changes: 43 additions & 0 deletions apps/invert_homography.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2012 Andreas Heider, Julius Adorf, Markus Grimm
*
* MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

#include "tpofinder/util.h"

#include <boost/program_options.hpp>

using namespace cv;
using namespace tpofinder;
using namespace std;
namespace bpo = boost::program_options;

int main(int argc, char** argv) {
bpo::options_description options;
string ifile, ofile;
options.add_options()
("in,i", bpo::value<string > (&ifile), "file where the "
"homography is read from.")
("out,o", bpo::value<string > (&ofile), "file where the inverted "
"homography is written to.");
bpo::positional_options_description posopts;
posopts.add("in", 1);
posopts.add("out", 1);

bpo::variables_map vm;
bpo::store(bpo::command_line_parser(argc, argv).
options(options).positional(posopts).run(), vm);
bpo::notify(vm);

if (ifile.empty() || ofile.empty()) {
cerr << "Usage: invert_homography <in-file> <out-file>" << endl;
options.print(cerr);
return -1;
}

invertHomography(ifile, ofile);

return 0;
}

96 changes: 96 additions & 0 deletions apps/model_homography.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright (c) 2012 Andreas Heider, Julius Adorf, Markus Grimm
*
* MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

#include "tpofinder/util.h"
#include "tpofinder/visualize.h"

#include <boost/format.hpp>
#include <boost/program_options.hpp>
#include <cstdlib>
#include <iostream>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace tpofinder;
using namespace std;
namespace bpo = boost::program_options;

int main(int argc, char** argv) {
string cfile, ofile;
string tfile, rfile;

bpo::options_description options;
options.add_options()
("correspondences,c", bpo::value<string > (&cfile), "path to a file "
"containing point correspondences. This file must be structured "
"as follows:\n\n"
"%YAML:1.0\n"
"train: !!opencv-matrix\n"
" rows: 4\n"
" cols: 1\n"
" dt: \"2f\"\n"
" data: [ 260., 157., 268., 305., 436., 291., 442., 158. ]\n"
"ref: !!opencv-matrix\n"
" rows: 4\n"
" cols: 1\n"
" dt: \"2f\"\n"
" data: [ 276., 198., 276., 348., 446., 348., 438., 212. ]\n\n"
"Here the matrices in 'data' are of the form [x1 y1 x2 y2 ... x4 y4]; "
"so put the points in the training image into one matrix and the "
"corresponding points in the reference image into the other.")
("out,o", bpo::value<string > (&ofile), "path to a file where the computed "
"homography shall be written to.")
("ref,r", bpo::value<string > (&rfile), "path to reference image (optional).")
("train,t", bpo::value<string > (&tfile), "path to train image (optional).");

bpo::variables_map vm;
bpo::store(bpo::parse_command_line(argc, argv, options), vm);
notify(vm);

Mat ref;
Mat train;

if (vm.count("correspondences") == 1) {
FileStorage in(cfile, FileStorage::READ);
in["ref"] >> ref;
in["train"] >> train;
in.release();
} else {
options.print(cerr);
return -1;
}

Mat homography = findHomography(ref, train);
cout << homography << endl;

if (!ofile.empty()) {
writeHomography(ofile, homography);
}

if (!rfile.empty() && !tfile.empty()) {
Mat refImg = imread(rfile);
Mat trainImg = imread(tfile);

Mat refPointsImg = refImg.clone();
Mat trainPointsImg = trainImg.clone();
for (int i = 0; i < ref.rows; i++) {
circle(refPointsImg, ref.at<Point2f>(i), 3, Scalar(255, 0, 0), CV_FILLED);
circle(trainPointsImg, train.at<Point2f>(i), 3, Scalar(255, 0, 0), CV_FILLED);
}
imshow("keys on reference image", refPointsImg);
imshow("keys on training image", trainPointsImg);

Mat out = blend(refImg, trainImg, homography);
string name = str(boost::format("homography: [%s] %s -> %s [%s]") % cfile % rfile % tfile % ofile);
imshow(name, out);
waitKey(0);
}

return 0;
}

38 changes: 38 additions & 0 deletions apps/sequence_homography.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2012 Andreas Heider, Julius Adorf, Markus Grimm
*
* MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

#include "tpofinder/truth.h"
#include "tpofinder/visualize.h"

using namespace cv;
using namespace tpofinder;
using namespace std;

int main(int /* argc */, char** /* argv */) {
cvStartWindowThread();
namedWindow("sequence_homography");

HomographySequenceEstimator estimator;
Mat firstImage;
while (true) {
string p;
getline(cin, p);
if (p.size() > 0) {
Mat image = imread(p, 0);
if (firstImage.empty()) {
firstImage = image;
}
Mat homography = estimator.next(image);

Mat out = blend(firstImage, image, homography);
imshow("sequence_homography", out);
waitKey(0);
}
}

return 0;
}

Loading

0 comments on commit f5e9917

Please sign in to comment.