Permalink
Browse files

Continuing work on the RMAX bundle adjustment code. There are numerou…

…s changes here, but most importantly this bring the stereo pipeline up to date with the latest changes to the Vision Workbench.
  • Loading branch information...
1 parent 7b66e8a commit b9d92423dd8db70eedc5c7f152865459a9b382d4 @broxtronix broxtronix committed Mar 11, 2008
Showing with 336 additions and 243 deletions.
  1. +2 −2 configure.ac
  2. +2 −2 src/Makefile.am
  3. +83 −84 src/RMAX/RMAX.h
  4. +52 −28 src/rmax2cahvor.cc
  5. +197 −127 src/rmax_adjust.cc
View
@@ -263,8 +263,8 @@ AX_APP(POINT2MESH, [src], yes, [BOOST BOOST_PROGRAM_OPTIONS VW OPENSCENEGRAPH])
AX_APP(POINT2DEM, [src], yes, [BOOST BOOST_PROGRAM_OPTIONS VW VW_CARTOGRAPHY])
AX_APP(NURBS, [src], no, [BOOST BOOST_PROGRAM_OPTIONS VW MBA])
AX_APP(CTXIMAGE, [src], no, [BOOST BOOST_PROGRAM_OPTIONS VW VW_CARTOGRAPHY])
-AX_APP(RMAX2CAHVOR, [src], no, [BOOST VW VW_CAMERA])
-AX_APP(RMAXADJUST, [src], no, [BOOST BOOST_PROGRAM_OPTIONS VW VW_CAMERA VW_STEREO LAPACK])
+AX_APP(RMAX2CAHVOR, [src], no, [BOOST VW VW_CAMERA BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM])
+AX_APP(RMAXADJUST, [src], no, [BOOST BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM VW VW_CAMERA VW_STEREO LAPACK])
##################################################
# final processing
View
@@ -96,13 +96,13 @@ endif
if MAKE_APP_RMAX2CAHVOR
bin_PROGRAMS += rmax2cahvor
- rmax2cahvor_SOURCES = rmax2cahvor.cc
+ rmax2cahvor_SOURCES = rmax2cahvor.cc RMAX/RMAX.cc
rmax2cahvor_LDFLAGS = $(APP_RMAX2CAHVOR_LIBS) $(ASP_LDFLAGS)
endif
if MAKE_APP_RMAXADJUST
bin_PROGRAMS += rmax_adjust
- rmax_adjust_SOURCES = rmax_adjust.cc
+ rmax_adjust_SOURCES = rmax_adjust.cc RMAX/RMAX.cc RMAX/RmaxInterestPoint.cc
rmax_adjust_LDFLAGS = $(APP_RMAXADJUST_LIBS) $(ASP_LDFLAGS)
endif
View
@@ -4,9 +4,13 @@
#include <string>
#include <vw/FileIO/DiskImageResourcePNG.h>
#include <vw/Camera/CAHVORModel.h>
+#include <vw/Camera/BundleAdjust.h>
+#include <vw/Core.h>
-#define RMAX_GLOBAL_EASTING (582680)
-#define RMAX_GLOBAL_NORTHING (4141480)
+using namespace vw;
+
+// Split filename into base and extension.
+int split_filename(const std::string& filename, std::string& base, std::string& extension);
struct ImageInfo {
std::string filename;
@@ -18,88 +22,83 @@ struct ImageInfo {
} camera;
};
-void read_image_info( std::string const& filename, ImageInfo& info ) {
- vw_out(DebugMessage) << "Reading image info from " << filename << std::endl;;
- DiskImageResourcePNG png( filename );
- info.filename = filename;
- for( unsigned i=0; i<png.num_comments(); ++i ) {
- std::string const& key = png.get_comment(i).key;
- std::istringstream value( png.get_comment(i).text );
- if( key == "easting" ) value >> info.easting;
- else if( key == "northing" ) value >> info.northing;
- else if( key == "heading" ) value >> info.heading;
- else if( key == "pitch" ) value >> info.pitch;
- else if( key == "roll" ) value >> info.roll;
- else if( key == "height" ) value >> info.height;
- // Note: The key name says it's in radians, but it's clearly actually in degrees!
- else if( key == "tilt angle in radians" ) value >> info.tilt;
- else if( key == "which camera" ) {
- switch( png.get_comment(i).text[0] ) {
- case 'l': info.camera = ImageInfo::LEFT; break;
- case 'r': info.camera = ImageInfo::RIGHT; break;
- case 'c': info.camera = ImageInfo::COLOR; break;
- }
- }
- //else std::cout << "Unkown key: " << key << std::endl;
+void read_image_info( std::string const& filename, ImageInfo& info );
+
+vw::camera::CAHVORModel rmax_image_camera_model( ImageInfo const& info,
+ vw::Vector3 const& position_correction,
+ vw::Vector3 const& pose_correction);
+
+vw::camera::CAHVORModel rmax_image_camera_model( ImageInfo const& info );
+
+vw::camera::CAHVORModel rmax_image_camera_model( std::string const& filename );
+
+bool may_overlap( ImageInfo const& i1, ImageInfo const& i2 );
+bool may_overlap( std::string const& file1, std::string const& file2 );
+
+class HelicopterBundleAdjustmentModel : public camera::BundleAdjustmentModelBase<HelicopterBundleAdjustmentModel, 6, 3> {
+ std::vector<ImageInfo> m_image_infos;
+ std::vector<Vector<double,6> > m_adjustments;
+
+public:
+ typedef camera::AdjustedCameraModel camera_type;
+
+ HelicopterBundleAdjustmentModel(std::vector<ImageInfo> const& image_infos) :
+ m_image_infos(image_infos), m_adjustments(image_infos.size()) {}
+
+ unsigned size() const { return m_image_infos.size(); }
+
+ void update(std::vector<Vector<double, camera_params_n> > a) {
+ m_adjustments = a;
}
-}
-
-vw::camera::CAHVORModel rmax_image_camera_model( ImageInfo const& info ) {
- CAHVORModel base;
- if( info.camera == ImageInfo::RIGHT ) {
- base.C = Vector3( 0.495334, -0.003158, -0.004600 );
- base.A = Vector3( 0.006871, -0.000863, 0.999976 );
- base.H = Vector3( 1095.653400, 8.513659, 321.246801 );
- base.V = Vector3( -7.076027, 1093.871625, 251.343361 );
- base.O = Vector3( 0.004817, 0.000619, 0.999988 );
- base.R = Vector3( 0.000000, -0.235833, 0.180509 );
+
+ void write_adjustment(int j, std::string const& filename) {
+ std::ofstream ostr(filename.c_str());
+ ostr << m_adjustments[j][0] << " " << m_adjustments[j][1] << " " << m_adjustments[j][2] << "\n";
+ ostr << m_adjustments[j][3] << " " << m_adjustments[j][4] << " " << m_adjustments[j][5] << "\n";
}
- else {
- base.C = Vector3( -0.495334, 0.003158, 0.004600 );
- base.A = Vector3( -0.000000, 0.000000, 1.000000 );
- base.H = Vector3( 1095.186165, -0.000000, 324.865834 );
- base.V = Vector3( 0.000000, 1095.678491, 250.561559 );
- base.O = Vector3( 0.000012, -0.002199, 0.999998 );
- base.R = Vector3( 0.000000, -0.230915, 0.128078 );
+
+ void write_adjusted_camera(int j, std::string const& filename) {
+ Vector<double,6> a_j = m_adjustments[j];
+ Vector3 position_correction = subvector(a_j, 0, 3);
+ Vector3 pose_correction = subvector(a_j, 3,3);
+ camera::CAHVORModel cam = rmax_image_camera_model(m_image_infos[j], position_correction, pose_correction);
+ cam.write(filename);
+ }
+
+ std::vector<boost::shared_ptr<camera::CameraModel> > adjusted_cameras() {
+ std::vector<boost::shared_ptr<camera::CameraModel> > result(m_adjustments.size());
+ for (unsigned j = 0; j < result.size(); ++j) {
+ Vector3 position_correction = subvector(m_adjustments[j], 0, 3);
+ Vector3 pose_correction = subvector(m_adjustments[j], 3,3);
+
+ camera::CAHVORModel* cahvor = new camera::CAHVORModel;
+ *cahvor = rmax_image_camera_model(m_image_infos[j], position_correction, pose_correction);
+
+ result[j] = boost::shared_ptr<camera::CameraModel>( cahvor );
+ }
+ return result;
}
- double cr=cos(info.roll*M_PI/180), sr=sin(info.roll*M_PI/180);
- double cp=cos(info.pitch*M_PI/180), sp=sin(info.pitch*M_PI/180);
- double cy=cos(info.heading*M_PI/180), sy=sin(info.heading*M_PI/180);
- Matrix3x3 roll, pitch, yaw, flip;
- roll(0,0)=cr; roll(0,1)=0; roll(0,2)=-sr;
- roll(1,0)=0; roll(1,1)=1; roll(1,2)=0;
- roll(2,0)=sr; roll(2,1)=0; roll(2,2)=cr;
- pitch(0,0)=1; pitch(0,1)=0; pitch(0,2)=0;
- // XXX Pitch might have the wrong sign here....
- pitch(1,0)=0; pitch(1,1)=cp; pitch(1,2)=-sp;
- pitch(2,0)=0; pitch(2,1)=sp; pitch(2,2)=cp;
- yaw(0,0)=cy; yaw(0,1)=-sy; yaw(0,2)=0;
- yaw(1,0)=sy; yaw(1,1)=cy; yaw(1,2)=0;
- yaw(2,0)=0; yaw(2,1)=0; yaw(2,2)=1;
- flip(0,0)=1; flip(0,1)=0; flip(0,2)=0;
- flip(1,0)=0; flip(1,1)=-1; flip(1,2)=0;
- flip(2,0)=0; flip(2,1)=0; flip(2,2)=-1;
- Matrix3x3 ori = flip*yaw*pitch*roll;
- Vector3 pos( info.easting, info.northing, info.height );
- CAHVORModel cahvor;
- cahvor.C = pos - Vector3(RMAX_GLOBAL_EASTING,RMAX_GLOBAL_NORTHING,0) + ori*base.C;
- cahvor.A = ori*base.A;
- cahvor.H = ori*base.H;
- cahvor.V = ori*base.V;
- cahvor.O = ori*base.O;
- cahvor.R = base.R;
- return cahvor;
-}
-
-vw::camera::CAHVORModel rmax_image_camera_model( std::string const& filename ) {
- ImageInfo info;
- read_image_info( filename, info );
- return rmax_image_camera_model( info );
-}
-
-bool may_overlap( ImageInfo const& i1, ImageInfo const& i2 ) {
- const double diameter = 6; // approximate diameter in meters
- return hypot( i2.easting-i1.easting, i2.northing-i1.northing ) < diameter;
-}
-
-#endif // RMAX_H__
+
+ // Given the 'a' vector (camera model parameters) for the j'th
+ // image, and the 'b' vector (3D point location) for the i'th
+ // point, return the location of b_i on imager j in pixel
+ // coordinates.
+ Vector2 operator() ( unsigned i, unsigned j, Vector<double,6> const& a_j, Vector<double,3> const& b_i ) {
+ Vector3 position_correction = subvector(a_j, 0, 3);
+ Vector3 pose_correction = subvector(a_j, 3,3);
+ camera::CAHVORModel cam = rmax_image_camera_model(m_image_infos[j], position_correction, pose_correction);
+ return cam.point_to_pixel(b_i);
+ }
+
+
+ virtual Vector2 error( unsigned i, unsigned j,
+ Vector2 const& x_ij,
+ Vector<double, 6> const& a_j,
+ Vector<double, 3> const& b_i ) {
+ return x_ij - this->operator()(i,j,a_j,b_i);
+ }
+
+ Vector<double,6> initial_parameters(unsigned j) const { return Vector<double,6>(); }
+};
+
+#endif // __RMAX_H__
View
@@ -10,45 +10,69 @@
#include <iostream>
#include <boost/algorithm/string.hpp>
+#include <boost/program_options.hpp>
+namespace po = boost::program_options;
#include <vw/Camera/CAHVORModel.h>
using namespace vw;
using namespace vw::camera;
#include "RMAX/RMAX.h"
-// Split filename into base and extension.
-int split_filename(const std::string& filename, std::string& base, std::string& extension) {
- std::string::size_type dot = filename.find_last_of('.');
- if(dot == std::string::npos || dot <= 0)
- return -1;
- extension = filename.substr(dot);
- boost::to_lower(extension);
- base = filename.substr(0, dot);
- return 0;
-}
-
int main(int argc, char* argv[]) {
- std::string base, extension, output;
- vw::camera::CAHVORModel cahvor;
+ std::string image_file;
+ std::string adjustment_filename;
- // If the command line wasn't properly formed or the user requested
- // help, we print a usage message.
- if(argc < 2 || split_filename(argv[1], base, extension) != 0 || extension != ".png") {
- std::cout << "USAGE: " << argv[0] << " input.png [output]" << std::endl;
- }
+ po::options_description general_options("Options");
+ general_options.add_options()
+ ("adjustment-file,a", po::value<std::string>(&adjustment_filename), "Apply adjustments from file.\n")
+ ("help", "Display this help message")
+ ("verbose", "Verbose output");
+
+ po::options_description hidden_options("");
+ hidden_options.add_options()
+ ("input-file", po::value<std::string>(&image_file));
+
+ po::options_description options("Allowed Options");
+ options.add(general_options).add(hidden_options);
- // Construct output filename.
- if(argc >= 3)
- output = argv[2];
- else
- output = base + ".cahvor";
+ po::positional_options_description p;
+ p.add("input-file", -1);
+
+ po::variables_map vm;
+ po::store( po::command_line_parser( argc, argv ).options(options).positional(p).run(), vm );
+ po::notify( vm );
- // Read CAHVOR camera model from image.
- cahvor = rmax_image_camera_model(argv[1]);
+ std::ostringstream usage;
+ usage << "Usage: " << argv[0] << " [options] <rmax image filenames>..." << std::endl << std::endl;
+ usage << general_options << std::endl;
- // Write CAHVOR camera model to file.
- cahvor.write(output);
+ if( vm.count("help") ) {
+ std::cout << usage << std::endl;
+ return 1;
+ }
- return 0;
+
+ std::string base, extension, output;
+ split_filename(image_file, base, extension);
+
+ if( vm.count("adjustment-file") ) {
+ ImageInfo info;
+ read_image_info( image_file, info );
+
+ std::ifstream f(adjustment_filename.c_str());
+ Vector3 position_adjustment;
+ Vector3 pose_adjustment;
+
+ f >> position_adjustment[0] >> position_adjustment[1] >> position_adjustment[2];
+ f >> pose_adjustment[0] >> pose_adjustment[1] >> pose_adjustment[2];
+ std::cout << position_adjustment << " " << pose_adjustment<< "\n";
+ CAHVORModel cahvor = rmax_image_camera_model(info, position_adjustment, pose_adjustment);
+ output = base + ".adjust.cahvor";
+ cahvor.write(output);
+ } else {
+ CAHVORModel cahvor = rmax_image_camera_model(argv[1]);
+ output = base + ".cahvor";
+ cahvor.write(output);
+ }
}
Oops, something went wrong.

0 comments on commit b9d9242

Please sign in to comment.