Skip to content

Commit

Permalink
IP matching: Only ISIS camera is single-threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Aug 22, 2014
1 parent 6fba2ff commit 2668806
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
24 changes: 17 additions & 7 deletions src/asp/Core/InterestPointMatching.cc
Expand Up @@ -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,
Expand Down Expand Up @@ -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<float>& m_tree;
IPListIter m_start, m_end;
ip::InterestPointList const& m_ip_other;
Expand All @@ -84,7 +87,8 @@ namespace asp {
Mutex& m_camera_mutex;
std::vector<size_t>::iterator m_output;
public:
EpipolarLineMatchTask( math::FLANNTree<float>& tree,
EpipolarLineMatchTask( bool single_threaded_camera,
math::FLANNTree<float>& tree,
ip::InterestPointList::const_iterator start,
ip::InterestPointList::const_iterator end,
ip::InterestPointList const& ip2,
Expand All @@ -95,6 +99,7 @@ namespace asp {
EpipolarLinePointMatcher const& matcher,
Mutex& camera_mutex,
std::vector<size_t>::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) {}
Expand All @@ -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<std::pair<float,int> > kept_indices;
Expand Down Expand Up @@ -195,15 +203,17 @@ namespace asp {
IPListIter end_it = start_it;
std::advance( end_it, ip1_size / number_of_jobs );
boost::shared_ptr<Task>
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 );
start_it = end_it;
std::advance( output_it, ip1_size / number_of_jobs );
}
boost::shared_ptr<Task>
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 );
Expand Down
17 changes: 12 additions & 5 deletions src/asp/Core/InterestPointMatching.h
Expand Up @@ -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
Expand Down Expand Up @@ -309,7 +311,8 @@ namespace asp {
// the images that that camera data doesn't know about. (ie
// scaling).
template <class Image1T, class Image2T>
bool ip_matching( vw::camera::CameraModel* cam1,
bool ip_matching( bool single_threaded_camera,
vw::camera::CameraModel* cam1,
vw::camera::CameraModel* cam2,
vw::ImageViewBase<Image1T> const& image1,
vw::ImageViewBase<Image2T> const& image2,
Expand All @@ -334,7 +337,9 @@ namespace asp {
// Match interest points forward/backward .. constraining on epipolar line
std::vector<size_t> 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;
Expand Down Expand Up @@ -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 <class Image1T, class Image2T>
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<Image1T> const& image1,
vw::ImageViewBase<Image2T> const& image2,
Expand Down Expand Up @@ -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<typename Image2T::pixel_type>(boost::math::isnan(nodata2) ? 0 : nodata2),
NearestPixelInterpolation()), raster_box),
Expand Down
8 changes: 4 additions & 4 deletions src/asp/Core/StereoSettings.cc
Expand Up @@ -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());
}
Expand All @@ -368,11 +367,12 @@ namespace asp {
}

po::basic_parsed_options<char>
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<char> 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."
Expand Down
3 changes: 2 additions & 1 deletion src/asp/Core/StereoSettings.h
Expand Up @@ -194,7 +194,8 @@ namespace asp {
bool allow_unregistered = false );

boost::program_options::basic_parsed_options<char>
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 );

Expand Down
3 changes: 2 additions & 1 deletion src/asp/Sessions/DG/StereoSessionDG.cc
Expand Up @@ -191,8 +191,9 @@ namespace asp {
}

DiskImageView<float> 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);
Expand Down
5 changes: 3 additions & 2 deletions src/asp/Sessions/ISIS/StereoSessionIsis.cc
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/asp/Sessions/NadirPinhole/StereoSessionNadirPinhole.cc
Expand Up @@ -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<float> 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);
Expand Down

0 comments on commit 2668806

Please sign in to comment.