00001
00005 #ifndef _THERMALSFM_SBA_H_
00006 #define _THERMALSFM_SBA_H_
00007
00008 #include "general_resources.hpp"
00009 #include "opencv_resources.hpp"
00010 #include "ros_resources.hpp"
00011 #include "reconstruction.hpp"
00012 #include "keyframes.hpp"
00013 #include "tracks.hpp"
00014
00015 #include <sba/sba.h>
00016 #include <sba/visualization.h>
00017
00018 #define DEFAULT_MAX_DISPLACEMENT 0.3
00019
00020
00021 #include <time.h>
00022
00023
00025 void normalizeSystem(SysSBA& sys, double factor = 1.0);
00026
00028 double determineSystemSize(SysSBA& sys);
00029
00030 double distanceBetweenPoints(Eigen::Matrix<double, 4, 1>& pt1, Eigen::Matrix<double, 4, 1>& pt2);
00031
00032 void drawKeyframes(const ros::Publisher &camera_pub, const geometry_msgs::PoseStamped *keyframePoses, unsigned int keyframeCount);
00033
00034 bool overwritePoints(const SysSBA& sys, const vector<int>& track_indices, vector<featureTrack>& tracks, double maxDisplacement = DEFAULT_MAX_DISPLACEMENT, double *averagePointShift = 0, bool debug = false);
00035
00036 void rescaleSBA(SysSBA& sba, unsigned int idx1, unsigned int idx2);
00037
00038 void findRelevantIndices(vector<featureTrack>& tracks, vector<unsigned int>& triangulated, vector<unsigned int>& untriangulated, unsigned int last_index, unsigned int new_index);
00039
00040 void optimizeFullSystem(vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, unsigned int last_index);
00041
00042 void findIntermediatePoses(vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, unsigned int image_idx_1, unsigned int image_idx_2, bool fixBothEnds = true);
00043
00044 double getFeatureMotion(vector<featureTrack>& tracks, vector<unsigned int>& indices, unsigned int idx_1, unsigned int idx_2);
00045
00046
00047
00048 void assignFullSystem(SysSBA &sba, vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, unsigned int start_index, unsigned int finish_index, bool dummy = false);
00049
00050 void assignPartialSystem(SysSBA &sba, vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, vector<unsigned int>& indices, bool assignProjections = true);
00051
00052 bool reconstructFreshSubsequencePair(vector<featureTrack>& tracks, vector<cv::Point3d>& ptCloud, vector<unsigned int>& triangulatedIndices, cv::Mat& real_C0, cv::Mat& real_C1, cameraParameters camData, int idx1, int idx2);
00053
00054 void subselectPoints(const vector<cv::Point2f>& src1, vector<cv::Point2f>& dst1, const vector<cv::Point2f>& src2, vector<cv::Point2f>& dst2);
00055
00056 int estimatePoseBetweenCameras(cameraParameters& camData, vector<cv::Point2f>& pts1, vector<cv::Point2f>& pts2, cv::Mat& C);
00057
00058 double optimizeSystem(SysSBA &sba, double err = 1e-3, int iterations = 100, bool debug = false, int mode = SBA_SPARSE_CHOLESKY);
00059
00060 double twoViewBundleAdjustment(cameraParameters cam_data, cv::Mat& cam1, cv::Mat& cam2, vector<cv::Point3d>& cloud, vector<cv::Point2f>& pts1, vector<cv::Point2f>& pts2, int iterations = 10);
00061
00062 void initializeFrameCamera(frame_common::CamParams& cam_params, const cv::Mat& newCamMat, int& maxx, int& maxy, const cv::Size& cameraSize);
00063
00064 void drawGraph2(const SysSBA &sba, const ros::Publisher &camera_pub, const ros::Publisher &point_pub, const ros::Publisher &path_pub, int decimation = 1, int bicolor = 0, double scale = 0.1);
00065
00066 void extractPointCloud(const SysSBA &sba, pcl::PointCloud<pcl::PointXYZ>& point_cloud);
00067
00068 void extractCameras(const SysSBA &sba, visualization_msgs::MarkerArray& cameraArray, visualization_msgs::Marker& marker_path);
00069
00070 void addPointsToSBA(SysSBA& sba, vector<cv::Point3d>& cloud);
00071
00072 void addProjectionsToSBA(SysSBA& sba, vector<cv::Point2f>& loc, int idx);
00073
00074 double optimizeKeyframePair(vector<featureTrack>& tracks, cameraParameters& camData, int idx1, int idx2, cv::Mat *cameras);
00075
00076 double testKeyframePair(vector<featureTrack>& tracks, cameraParameters& camData, double *scorecard[], int idx1, int idx2, double *scores, cv::Mat& pose, bool evaluate = false, bool debug = false);
00077
00078 void addProjectionToSBA(SysSBA& sba, cv::Point2f& loc, unsigned int trackNo, unsigned int camNo);
00079
00080 void removePoorTracks(vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, unsigned int start_cam, unsigned int finish_cam);
00081
00082 double keyframeBundleAdjustment(cameraParameters& camData, vector<featureTrack>& tracks, cv::Mat *cameras, vector<unsigned int>& indices, unsigned int iterations = 100, bool allFree = false, bool allFixedExceptLast = false, unsigned fixed_cams = 0);
00083
00084 double keyframeBundleAdjustment(cameraParameters& camData, vector<featureTrack>& tracks, keyframeStore& kf_store, cv::Mat *cameras, unsigned int kfIndex, unsigned int iterations = 100);
00085
00086 double predictiveBundleAdjustment(cameraParameters& camData, vector<featureTrack>& tracks, geometry_msgs::PoseStamped *keyframePoses, bool *keyframeTypes, unsigned int keyframeCount, geometry_msgs::PoseStamped& newPose, unsigned int iterations = 100, bool debug = false, int mode = SBA_SPARSE_CHOLESKY, double err = 1e-3, int *triangulations = 0, double *averagePointShift = 0);
00087
00088 double odometryBundleAdjustment(cameraParameters& camData, vector<featureTrack>& tracks, geometry_msgs::PoseStamped *keyframePoses, unsigned int keyframeCount, unsigned int iterations = 100, bool debug = false);
00089
00090 void getActiveCameras(cv::Mat *C, vector<unsigned int>& indices, unsigned int min_index, unsigned int max_index);
00091
00092 void getActiveTracks(vector<featureTrack>& tracks, vector<unsigned int>& cameras, vector<unsigned int>& indices);
00093 void assignSystem(SysSBA &sba, vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, vector<unsigned int>& camera_indices, vector<unsigned int>& track_indices);
00094 void retrieveSystem(SysSBA &sba, vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, vector<unsigned int>& camera_indices, vector<unsigned int>& track_indices);
00095
00096 void retrieveFullSystem(SysSBA& sys, cv::Mat *C, vector<featureTrack>& tracks, unsigned int start_cam, unsigned int final_cam);
00097
00098 double adjustFullSystem(vector<featureTrack>& tracks, cameraParameters& camData, cv::Mat *cameras, unsigned int min_index, unsigned int max_index, unsigned int its = 1);
00099
00100 void retrievePartialSystem(SysSBA& sys, cv::Mat *C, vector<featureTrack>& tracks, vector<unsigned int>& indices);
00101
00102
00103
00104
00105
00106 void renormalizeSBA(SysSBA& sba, cv::Point3d& desiredCenter);
00107
00108 void findCentroid(SysSBA& sba, cv::Point3d& centroid, cv::Point3d& stdDeviation);
00109
00110 void copySys(const SysSBA& src, SysSBA& dst);
00111
00112 double optimizeSubsystem(cameraParameters& camData, cv::Mat *C, vector<unsigned int>& c_i, vector<featureTrack>& tracks, vector<unsigned int>& t_i, unsigned int iterations = 100);
00113
00114 void finishTracks(vector<featureTrack>& tracks, vector<cv::Point2f>& pts, double retainProp = 0.80, unsigned int maxOccurrences = 0);
00115 #endif