From 2668806bdef8ffca08b1448e549ee5668ec9f9ca Mon Sep 17 00:00:00 2001 From: Oleg Alexandrov Date: Fri, 22 Aug 2014 15:38:38 -0700 Subject: [PATCH] IP matching: Only ISIS camera is single-threaded --- src/asp/Core/InterestPointMatching.cc | 24 +++++++++++++------ src/asp/Core/InterestPointMatching.h | 17 +++++++++---- src/asp/Core/StereoSettings.cc | 8 +++---- src/asp/Core/StereoSettings.h | 3 ++- src/asp/Sessions/DG/StereoSessionDG.cc | 3 ++- src/asp/Sessions/ISIS/StereoSessionIsis.cc | 5 ++-- .../NadirPinhole/StereoSessionNadirPinhole.cc | 5 ++-- 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/asp/Core/InterestPointMatching.cc b/src/asp/Core/InterestPointMatching.cc index 9c304e1a1..f8e7c586c 100644 --- a/src/asp/Core/InterestPointMatching.cc +++ b/src/asp/Core/InterestPointMatching.cc @@ -26,9 +26,11 @@ using namespace vw; namespace asp { - EpipolarLinePointMatcher::EpipolarLinePointMatcher( double threshold, double epipolar_threshold, + EpipolarLinePointMatcher::EpipolarLinePointMatcher( bool single_threaded_camera, + double threshold, double epipolar_threshold, vw::cartography::Datum const& datum ) : - m_threshold(threshold), m_epipolar_threshold(epipolar_threshold), m_datum(datum) {} + m_single_threaded_camera(single_threaded_camera), m_threshold(threshold), + m_epipolar_threshold(epipolar_threshold), m_datum(datum) {} Vector3 EpipolarLinePointMatcher::epipolar_line( Vector2 const& feature, cartography::Datum const& datum, @@ -75,6 +77,7 @@ namespace asp { class EpipolarLineMatchTask : public Task, private boost::noncopyable { typedef ip::InterestPointList::const_iterator IPListIter; + bool m_single_threaded_camera; math::FLANNTree& m_tree; IPListIter m_start, m_end; ip::InterestPointList const& m_ip_other; @@ -84,7 +87,8 @@ namespace asp { Mutex& m_camera_mutex; std::vector::iterator m_output; public: - EpipolarLineMatchTask( math::FLANNTree& tree, + EpipolarLineMatchTask( bool single_threaded_camera, + math::FLANNTree& tree, ip::InterestPointList::const_iterator start, ip::InterestPointList::const_iterator end, ip::InterestPointList const& ip2, @@ -95,6 +99,7 @@ namespace asp { EpipolarLinePointMatcher const& matcher, Mutex& camera_mutex, std::vector::iterator output ) : + m_single_threaded_camera(single_threaded_camera), m_tree(tree), m_start(start), m_end(end), m_ip_other(ip2), m_cam1(cam1), m_cam2(cam2), m_tx1(tx1), m_tx2(tx2), m_matcher( matcher ), m_camera_mutex(camera_mutex), m_output(output) {} @@ -110,11 +115,14 @@ namespace asp { Vector3 line_eq; bool found_epipolar; - { - // Can't assume the camera is thread safe (ISIS) + if (m_single_threaded_camera){ + // ISIS camera is single-threaded Mutex::Lock lock( m_camera_mutex ); line_eq = m_matcher.epipolar_line( ip_org_coord, m_matcher.m_datum, m_cam1, m_cam2, found_epipolar); + }else{ + line_eq = m_matcher.epipolar_line( ip_org_coord, m_matcher.m_datum, m_cam1, m_cam2, + found_epipolar); } std::vector > kept_indices; @@ -195,7 +203,8 @@ namespace asp { IPListIter end_it = start_it; std::advance( end_it, ip1_size / number_of_jobs ); boost::shared_ptr - match_task( new EpipolarLineMatchTask( kd, start_it, end_it, + match_task( new EpipolarLineMatchTask( m_single_threaded_camera, + kd, start_it, end_it, ip2, cam1, cam2, tx1, tx2, *this, camera_mutex, output_it ) ); matching_queue.add_task( match_task ); @@ -203,7 +212,8 @@ namespace asp { std::advance( output_it, ip1_size / number_of_jobs ); } boost::shared_ptr - match_task( new EpipolarLineMatchTask( kd, start_it, ip1.end(), + match_task( new EpipolarLineMatchTask( m_single_threaded_camera, + kd, start_it, ip1.end(), ip2, cam1, cam2, tx1, tx2, *this, camera_mutex, output_it ) ); matching_queue.add_task( match_task ); diff --git a/src/asp/Core/InterestPointMatching.h b/src/asp/Core/InterestPointMatching.h index 4a67a90e3..f9ec19dc0 100644 --- a/src/asp/Core/InterestPointMatching.h +++ b/src/asp/Core/InterestPointMatching.h @@ -41,11 +41,13 @@ namespace asp { // threshold. The remaining 2 or then selected to be a match if // their distance meets the other threshold. class EpipolarLinePointMatcher { + bool m_single_threaded_camera; double m_threshold, m_epipolar_threshold; vw::cartography::Datum m_datum; public: - EpipolarLinePointMatcher( double threshold, double epipolar_threshold, + EpipolarLinePointMatcher( bool single_threaded_camera, + double threshold, double epipolar_threshold, vw::cartography::Datum const& datum ); // This only returns the indicies @@ -309,7 +311,8 @@ namespace asp { // the images that that camera data doesn't know about. (ie // scaling). template - bool ip_matching( vw::camera::CameraModel* cam1, + bool ip_matching( bool single_threaded_camera, + vw::camera::CameraModel* cam1, vw::camera::CameraModel* cam2, vw::ImageViewBase const& image1, vw::ImageViewBase const& image2, @@ -334,7 +337,9 @@ namespace asp { // Match interest points forward/backward .. constraining on epipolar line std::vector forward_match, backward_match; vw_out() << "\t--> Matching interest points" << std::endl; - EpipolarLinePointMatcher matcher( 0.5, norm_2(Vector2(image1.impl().cols(),image1.impl().rows()))/20, datum ); + EpipolarLinePointMatcher matcher(single_threaded_camera, + 0.5, norm_2(Vector2(image1.impl().cols(), + image1.impl().rows()))/20, datum ); vw_out() << "\t Matching Forward" << std::endl; matcher( ip1, ip2, cam1, cam2, left_tx, right_tx, forward_match ); vw_out() << "\t Matching Backward" << std::endl; @@ -429,7 +434,8 @@ namespace asp { // apply a homogrpahy to make right image like left image. This is // useful so that both images have similar scale and similar affine qualities. template - bool ip_matching_w_alignment( vw::camera::CameraModel* cam1, + bool ip_matching_w_alignment( bool single_threaded_camera, + vw::camera::CameraModel* cam1, vw::camera::CameraModel* cam2, vw::ImageViewBase const& image1, vw::ImageViewBase const& image2, @@ -474,7 +480,8 @@ namespace asp { // next step. Using anything else will interpolate nodata values // and stop them from being masked out. bool inlier = - ip_matching( cam1, cam2, image1.impl(), + ip_matching( single_threaded_camera, + cam1, cam2, image1.impl(), crop(transform(image2.impl(), compose(tx, inverse(right_tx)), ValueEdgeExtension(boost::math::isnan(nodata2) ? 0 : nodata2), NearestPixelInterpolation()), raster_box), diff --git a/src/asp/Core/StereoSettings.cc b/src/asp/Core/StereoSettings.cc index e624a7623..2f885522b 100644 --- a/src/asp/Core/StereoSettings.cc +++ b/src/asp/Core/StereoSettings.cc @@ -352,8 +352,7 @@ namespace asp { const po::option_description& d = *options[i]; if (d.long_name().empty()) - boost::throw_exception( - po::error("long name required for config file")); + boost::throw_exception(po::error("long name required for config file")); allowed_options.insert(d.long_name()); } @@ -368,11 +367,12 @@ namespace asp { } po::basic_parsed_options - parse_asp_config_file( std::string const& filename, + parse_asp_config_file( bool print_warning, + std::string const& filename, const po::options_description& desc, bool allow_unregistered ) { std::basic_ifstream strm(filename.c_str()); - if (!strm) { + if (!strm && print_warning) { vw_out(WarningMessage) << "Stereo file: " << filename << " could not be found. " << "Will use default settings and command line options only." diff --git a/src/asp/Core/StereoSettings.h b/src/asp/Core/StereoSettings.h index ca17c2d8d..5c0c853da 100644 --- a/src/asp/Core/StereoSettings.h +++ b/src/asp/Core/StereoSettings.h @@ -194,7 +194,8 @@ namespace asp { bool allow_unregistered = false ); boost::program_options::basic_parsed_options - parse_asp_config_file( std::string const&, + parse_asp_config_file( bool print_warning, + std::string const&, const boost::program_options::options_description&, bool allow_unregistered = false ); diff --git a/src/asp/Sessions/DG/StereoSessionDG.cc b/src/asp/Sessions/DG/StereoSessionDG.cc index 40f093ac3..f506d87dd 100644 --- a/src/asp/Sessions/DG/StereoSessionDG.cc +++ b/src/asp/Sessions/DG/StereoSessionDG.cc @@ -191,8 +191,9 @@ namespace asp { } DiskImageView image1( input_file1 ), image2( input_file2 ); + bool single_threaded_camera = false; bool inlier = - ip_matching_w_alignment( cam1, cam2, + ip_matching_w_alignment( single_threaded_camera, cam1, cam2, image1, image2, cartography::Datum("WGS84"), match_filename, nodata1, nodata2); diff --git a/src/asp/Sessions/ISIS/StereoSessionIsis.cc b/src/asp/Sessions/ISIS/StereoSessionIsis.cc index 358dfb45a..3fb3f6042 100644 --- a/src/asp/Sessions/ISIS/StereoSessionIsis.cc +++ b/src/asp/Sessions/ISIS/StereoSessionIsis.cc @@ -240,9 +240,10 @@ bool asp::StereoSessionIsis::ip_matching(std::string const& input_file1, ArgumentErr() << "StereoSessionISIS: Invalid left camera.\n" ); Vector3 radii = isis_cam->target_radii(); cartography::Datum datum("","","", (radii[0] + radii[1]) / 2, radii[2], 0); - + + bool single_threaded_camera = true; bool inlier = - ip_matching_w_alignment( cam1, cam2, + ip_matching_w_alignment( single_threaded_camera, cam1, cam2, image1, image2, datum, match_filename, nodata1, nodata2); diff --git a/src/asp/Sessions/NadirPinhole/StereoSessionNadirPinhole.cc b/src/asp/Sessions/NadirPinhole/StereoSessionNadirPinhole.cc index fd879eefc..e7bd5b2cb 100644 --- a/src/asp/Sessions/NadirPinhole/StereoSessionNadirPinhole.cc +++ b/src/asp/Sessions/NadirPinhole/StereoSessionNadirPinhole.cc @@ -65,10 +65,11 @@ bool StereoSessionNadirPinhole::ip_matching(std::string const& input_file1, vw_out() << "\t--> Using cached match file: " << match_filename << "\n"; return true; } - + DiskImageView image1( input_file1 ), image2( input_file2 ); + bool single_threaded_camera = false; bool inlier = - ip_matching_w_alignment( cam1, cam2, + ip_matching_w_alignment( single_threaded_camera, cam1, cam2, image1, image2, cartography::Datum("WGS84"), match_filename, nodata1, nodata2);