diff --git a/.gitignore b/.gitignore index e97b472..ec24250 100644 --- a/.gitignore +++ b/.gitignore @@ -342,4 +342,7 @@ ASALocalRun/ healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ \ No newline at end of file +MigrationBackup/ + +# Specific to this report +results/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f8796d2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,121 @@ +cmake_minimum_required(VERSION 3.8) + +project(GraphCut_RANSAC LANGUAGES CXX) + +# indicate if OPENMP should be enabled +option(USE_OPENMP "Use OPENMP" ON) + +# ============================================================================== +# Check C++17 support +# ============================================================================== +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# ============================================================================== +# Find OpenCV +# ============================================================================== +find_package(OpenCV 3.3 REQUIRED) + +# ============================================================================== +# Find OpenMP +# ============================================================================== +find_package(OpenMP) +if (USE_OPENMP) + if(NOT OPENMP_FOUND) + message(FATAL_ERROR "OPENMP not found.") + endif() + add_definitions(-DUSE_OPENMP) + set(TRGT_LNK_LBS_ADDITIONAL OpenMP::OpenMP_CXX) +endif (USE_OPENMP) + +# ============================================================================== +# Includes +# ============================================================================== +include_directories ( + ${PROJECT_SOURCE_DIR}/include/GraphCut_RANSAC +) + +# ============================================================================== +# Structure: Library +# ============================================================================== +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) + +# Set header files for the library +file(GLOB_RECURSE HDRS_GCRANSAC + "include/GraphCut_RANSAC/*.h" + "include/GraphCut_RANSAC/*.cpp" +) + +# Set source files to be added to the library +file(GLOB_RECURSE SRCS_GCRANSAC + "src/GraphCut_RANSAC/*.cpp" +) + +source_group(third_pary\\GCOptimization FILES + src/GraphCut_RANSAC/GCoptimization.cpp + include/GraphCut_RANSAC/graph.cpp + src/GraphCut_RANSAC/LinkedBlockList.cpp + include/GraphCut_RANSAC/maxflow.cpp + include/GraphCut_RANSAC/block.h + include/GraphCut_RANSAC/energy.h + include/GraphCut_RANSAC/GCoptimization.h + include/GraphCut_RANSAC/graph.h + include/GraphCut_RANSAC/LinkedBlockList.h +) + +source_group(third_pary\\Theia FILES + include/GraphCut_RANSAC/prosac.h + include/GraphCut_RANSAC/prosac_sampler.h + include/GraphCut_RANSAC/quality_measurement.h + include/GraphCut_RANSAC/sample_consensus_estimator.h + include/GraphCut_RANSAC/sampler.h + include/GraphCut_RANSAC/inline_support.h + include/GraphCut_RANSAC/estimator.h +) + +add_library(${PROJECT_NAME} STATIC + ${HDRS_GCRANSAC} + ${SRCS_GCRANSAC} +) + +target_link_libraries(${PROJECT_NAME} + ${OpenCV_LIBS} +) + +# ============================================================================== +# Structure: Applications +# ============================================================================== +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin) + + +# five_point +file(GLOB_RECURSE HDRSSRCS_FIVE_POINT + "src/Sample_FundamentalEstimator/five_point/*.*" +) +source_group(third_pary\\five_point FILES + ${HDRSSRCS_FIVE_POINT} +) + +# estimators +source_group("Estimators" FILES + src/Sample_FundamentalEstimator/essential_estimator.h + src/Sample_FundamentalEstimator/fundamental_estimator.h + src/Sample_FundamentalEstimator/homography_estimator.h + src/Sample_FundamentalEstimator/line_estimator.h +) + + +add_executable(Sample_FundamentalEstimator + ${HDRSSRCS_FIVE_POINT} + src/Sample_FundamentalEstimator/essential_estimator.h + src/Sample_FundamentalEstimator/fundamental_estimator.h + src/Sample_FundamentalEstimator/homography_estimator.h + src/Sample_FundamentalEstimator/line_estimator.h + src/Sample_FundamentalEstimator/main.cpp) + +target_link_libraries(Sample_FundamentalEstimator + ${OpenCV_LIBS} + ${PROJECT_NAME} +) +add_dependencies(Sample_FundamentalEstimator ${PROJECT_NAME}) diff --git a/include/GraphCut_RANSAC/GCRANSAC.h b/include/GraphCut_RANSAC/GCRANSAC.h index c8fc6f0..c626226 100644 --- a/include/GraphCut_RANSAC/GCRANSAC.h +++ b/include/GraphCut_RANSAC/GCRANSAC.h @@ -681,8 +681,10 @@ Score GCRANSAC::get_score(const cv::Mat &points_, std::vector process_scores(process_number, { 0,0 }); - concurrency::parallel_for(0, process_number, [&](int process) - { +#ifdef USE_OPENMP +#pragma omp for +#endif + for (int process = 0; process < process_number; process++) { if (store_inliers_) process_inliers[process].reserve(step_size); const int start_idx = process * step_size; @@ -702,7 +704,7 @@ Score GCRANSAC::get_score(const cv::Mat &points_, process_scores[process].J += 1.0f - distance * distance / truncated_threshold_2; // Truncated quadratic cost } } - }); + } for (auto i = 0; i < process_number; ++i) { diff --git a/include/GraphCut_RANSAC/estimator.h b/include/GraphCut_RANSAC/estimator.h index 4edd463..0c6f04b 100644 --- a/include/GraphCut_RANSAC/estimator.h +++ b/include/GraphCut_RANSAC/estimator.h @@ -98,11 +98,13 @@ namespace theia const Model& model) const { std::vector residuals(data.size()); - concurrency::parallel_for(0, (int)data.size(), [&](int i) - //for (int i = 0; i < data.size(); i++) +#ifdef USE_OPENMP +#pragma omp parallel for +#endif + for (int i = 0; i < data.size(); i++) { residuals[i] = Error(data[i], model); - }); + } return residuals; } diff --git a/include/GraphCut_RANSAC/prosac_sampler.h b/include/GraphCut_RANSAC/prosac_sampler.h index c3ee416..01ab73a 100644 --- a/include/GraphCut_RANSAC/prosac_sampler.h +++ b/include/GraphCut_RANSAC/prosac_sampler.h @@ -42,7 +42,6 @@ #include #include "sampler.h" -#include "random.h" namespace theia { diff --git a/src/Sample/essential_estimator.h b/src/Sample_FundamentalEstimator/essential_estimator.h similarity index 99% rename from src/Sample/essential_estimator.h rename to src/Sample_FundamentalEstimator/essential_estimator.h index 2f83c53..cc20722 100644 --- a/src/Sample/essential_estimator.h +++ b/src/Sample_FundamentalEstimator/essential_estimator.h @@ -1,12 +1,10 @@ -#include "stdafx.h" - #include #include #include #include #include -#include "5point.h" +#include "five_point/5point.h" #include "estimator.h" #include "prosac.h" diff --git a/src/Sample/five_point/5point.cpp b/src/Sample_FundamentalEstimator/five_point/5point.cpp similarity index 100% rename from src/Sample/five_point/5point.cpp rename to src/Sample_FundamentalEstimator/five_point/5point.cpp diff --git a/src/Sample/five_point/5point.h b/src/Sample_FundamentalEstimator/five_point/5point.h similarity index 100% rename from src/Sample/five_point/5point.h rename to src/Sample_FundamentalEstimator/five_point/5point.h diff --git a/src/Sample/five_point/Mblock.h b/src/Sample_FundamentalEstimator/five_point/Mblock.h similarity index 100% rename from src/Sample/five_point/Mblock.h rename to src/Sample_FundamentalEstimator/five_point/Mblock.h diff --git a/src/Sample/five_point/Polynomial.h b/src/Sample_FundamentalEstimator/five_point/Polynomial.h similarity index 100% rename from src/Sample/five_point/Polynomial.h rename to src/Sample_FundamentalEstimator/five_point/Polynomial.h diff --git a/src/Sample/five_point/Rpoly.cpp b/src/Sample_FundamentalEstimator/five_point/Rpoly.cpp similarity index 100% rename from src/Sample/five_point/Rpoly.cpp rename to src/Sample_FundamentalEstimator/five_point/Rpoly.cpp diff --git a/src/Sample/five_point/Rpoly.h b/src/Sample_FundamentalEstimator/five_point/Rpoly.h similarity index 100% rename from src/Sample/five_point/Rpoly.h rename to src/Sample_FundamentalEstimator/five_point/Rpoly.h diff --git a/src/Sample/fundamental_estimator.h b/src/Sample_FundamentalEstimator/fundamental_estimator.h similarity index 99% rename from src/Sample/fundamental_estimator.h rename to src/Sample_FundamentalEstimator/fundamental_estimator.h index ca16d63..1168588 100644 --- a/src/Sample/fundamental_estimator.h +++ b/src/Sample_FundamentalEstimator/fundamental_estimator.h @@ -1,5 +1,3 @@ -#include "stdafx.h" - #include #include #include diff --git a/src/Sample/homography_estimator.h b/src/Sample_FundamentalEstimator/homography_estimator.h similarity index 98% rename from src/Sample/homography_estimator.h rename to src/Sample_FundamentalEstimator/homography_estimator.h index dd536c1..4de6f2a 100644 --- a/src/Sample/homography_estimator.h +++ b/src/Sample_FundamentalEstimator/homography_estimator.h @@ -1,8 +1,8 @@ -#include "stdafx.h" - #include "estimator.h" #include "prosac.h" +#include + using namespace theia; struct Homography diff --git a/src/Sample/line_estimator.h b/src/Sample_FundamentalEstimator/line_estimator.h similarity index 99% rename from src/Sample/line_estimator.h rename to src/Sample_FundamentalEstimator/line_estimator.h index 9b04761..1f6887c 100644 --- a/src/Sample/line_estimator.h +++ b/src/Sample_FundamentalEstimator/line_estimator.h @@ -1,5 +1,3 @@ -#include "stdafx.h" - #include #include #include diff --git a/src/Sample/main.cpp b/src/Sample_FundamentalEstimator/main.cpp similarity index 92% rename from src/Sample/main.cpp rename to src/Sample_FundamentalEstimator/main.cpp index 9117522..52549ea 100644 --- a/src/Sample/main.cpp +++ b/src/Sample_FundamentalEstimator/main.cpp @@ -1,24 +1,24 @@ -// VisionFrameWork.cpp : Defines the entry point for the console application. +// main.cpp : Defines the entry point for the console application. // -#include "stdafx.h" - -#include +#include #include -#include -#include -#include -#include -#include "opencv2/xfeatures2d.hpp" #include -#include +#include +#include +#include + +#include +#include +#include +#include + #include "GCRANSAC.h" -#include #include -#include "line_estimator.cpp" -#include "essential_estimator.cpp" -#include "fundamental_estimator.cpp" -#include "homography_estimator.cpp" +#include "line_estimator.h" +#include "essential_estimator.h" +#include "fundamental_estimator.h" +#include "homography_estimator.h" #include #include @@ -69,8 +69,10 @@ int main(int argc, const char* argv[]) std::string task = "head"; + const std::string root_dir = "../"; + // Create the task directory of doesn't exist - std::string dir = "results/" + task; + std::string dir = root_dir + "results/" + task; if (stat(dir.c_str(), &info) != 0) if (_mkdir(dir.c_str()) != 0) @@ -79,11 +81,11 @@ int main(int argc, const char* argv[]) return -1; } - std::string srcImagePath = "data/" + task + "/" + task + "1.jpg"; - std::string dstImagePath = "data/" + task + "/" + task + "2.jpg"; - std::string input_correspondence_path = "results/" + task + "/" + task + "_points_with_no_annotation.txt"; - std::string output_correspondence_path = "results/" + task + "/result_" + task + ".txt"; - std::string output_matchImagePath = "results/" + task + "/matches_" + task + ".png"; + std::string srcImagePath = root_dir + "data/" + task + "/" + task + "1.jpg"; + std::string dstImagePath = root_dir + "data/" + task + "/" + task + "2.jpg"; + std::string input_correspondence_path = root_dir + "results/" + task + "/" + task + "_points_with_no_annotation.txt"; + std::string output_correspondence_path = root_dir + "results/" + task + "/result_" + task + ".txt"; + std::string output_matchImagePath = root_dir + "results/" + task + "/matches_" + task + ".png"; const float confidence = 0.99f; const int fps = -1;