-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added set of minor bug fixes, and added code for infrastructure-based…
… calibration.
- Loading branch information
hengli
committed
Sep 16, 2013
1 parent
67623f4
commit b9c8e2a
Showing
17 changed files
with
2,184 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
153 changes: 153 additions & 0 deletions
153
include/camodocal/infrastr_calib/InfrastructureCalibration.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#ifndef INFRASTRUCTURECALIBRATION_H | ||
#define INFRASTRUCTURECALIBRATION_H | ||
|
||
#include <boost/thread.hpp> | ||
|
||
#include "camodocal/camera_models/Camera.h" | ||
#include "camodocal/camera_systems/CameraRigExtrinsics.h" | ||
#include "camodocal/sparse_graph/SparseGraph.h" | ||
|
||
#ifdef VCHARGE_VIZ | ||
#include "../../../../../visualization/overlay/GLOverlayExtended.h" | ||
#endif | ||
|
||
namespace camodocal | ||
{ | ||
|
||
// forward declaration | ||
class LocationRecognition; | ||
|
||
class InfrastructureCalibration | ||
{ | ||
public: | ||
InfrastructureCalibration(std::vector<CameraPtr>& cameras, | ||
bool verbose = false); | ||
|
||
bool loadMap(const std::string& mapDirectory); | ||
|
||
void addFrameSet(const std::vector<cv::Mat>& images, | ||
uint64_t timestamp, bool preprocess); | ||
void addOdometry(double x, double y, double yaw, uint64_t timestamp); | ||
|
||
void reset(void); | ||
void run(void); | ||
|
||
void loadFrameSets(const std::string& filename); | ||
void saveFrameSets(const std::string& filename) const; | ||
|
||
const CameraRigExtrinsics& extrinsics(void) const; | ||
|
||
private: | ||
void estimateCameraPose(const cv::Mat& image, uint64_t timestamp, | ||
FramePtr& frame, bool preprocess = false); | ||
void optimize(bool optimizeScenePoints); | ||
|
||
cv::Mat buildDescriptorMat(const std::vector<Point2DFeaturePtr>& features, | ||
std::vector<size_t>& indices) const; | ||
std::vector<cv::DMatch> matchFeatures(const std::vector<Point2DFeaturePtr>& queryFeatures, | ||
const std::vector<Point2DFeaturePtr>& trainFeatures) const; | ||
void rectifyImagePoint(const CameraConstPtr& camera, | ||
const cv::Point2f& src, cv::Point2f& dst) const; | ||
|
||
double reprojectionError(const CameraConstPtr& camera, | ||
const Eigen::Vector3d& P, | ||
const Eigen::Quaterniond& cam_ref_q, | ||
const Eigen::Vector3d& cam_ref_t, | ||
const Eigen::Vector3d& ref_p, | ||
const Eigen::Vector3d& ref_att, | ||
const Eigen::Vector2d& observed_p) const; | ||
|
||
void frameReprojectionError(const FramePtr& frame, | ||
const CameraConstPtr& camera, | ||
const Pose& T_cam_ref, | ||
double& minError, double& maxError, double& avgError, | ||
size_t& featureCount) const; | ||
|
||
void frameReprojectionError(const FramePtr& frame, | ||
const CameraConstPtr& camera, | ||
double& minError, double& maxError, double& avgError, | ||
size_t& featureCount) const; | ||
|
||
void reprojectionError(double& minError, double& maxError, | ||
double& avgError, size_t& featureCount) const; | ||
|
||
// Compute the quaternion average using the Markley SVD method | ||
template <typename FloatT> | ||
Eigen::Quaternion<FloatT> quaternionAvg(const std::vector<Eigen::Quaternion<FloatT> >& points) const; | ||
|
||
#ifdef VCHARGE_VIZ | ||
enum MapType | ||
{ | ||
REFERENCE_MAP, | ||
REFERENCE_POINTS | ||
}; | ||
|
||
void visualizeMap(const std::string& overlayName, MapType type) const; | ||
void visualizeCameraPose(const FrameConstPtr& frame, | ||
bool showScenePoints); | ||
void visualizeCameraPoses(bool showScenePoints); | ||
void visualizeExtrinsics(void) const; | ||
void visualizeOdometry(void) const; | ||
#endif | ||
|
||
typedef struct | ||
{ | ||
uint64_t timestamp; | ||
std::vector<FramePtr> frames; | ||
} FrameSet; | ||
|
||
// inputs | ||
std::vector<CameraPtr> m_cameras; | ||
SparseGraph m_refGraph; | ||
|
||
// working data | ||
boost::shared_ptr<LocationRecognition> m_locrec; | ||
boost::mutex m_feature3DMapMutex; | ||
boost::unordered_map<Point3DFeature*, Point3DFeaturePtr> m_feature3DMap; | ||
std::vector<FrameSet> m_framesets; | ||
double m_x_last; | ||
double m_y_last; | ||
double m_distance; | ||
bool m_verbose; | ||
|
||
#ifdef VCHARGE_VIZ | ||
vcharge::GLOverlayExtended m_overlay; | ||
#endif | ||
|
||
// output | ||
CameraRigExtrinsics m_extrinsics; | ||
|
||
// parameters | ||
const float k_maxDistanceRatio; | ||
const int k_minCorrespondences2D2D; | ||
const int k_minCorrespondences2D3D; | ||
const double k_minKeyFrameDistance; | ||
const int k_nearestImageMatches; | ||
const double k_nominalFocalLength; | ||
const double k_reprojErrorThresh; | ||
}; | ||
|
||
template <typename FloatT> | ||
Eigen::Quaternion<FloatT> | ||
InfrastructureCalibration::quaternionAvg(const std::vector<Eigen::Quaternion<FloatT> >& points) const | ||
{ | ||
using namespace Eigen; | ||
|
||
Matrix<FloatT, 3, 3> sum; | ||
sum.setZero(); | ||
for (int i = 0, end = points.size(); i != end; ++i) | ||
{ | ||
sum += points[i].toRotationMatrix(); | ||
} | ||
|
||
JacobiSVD<Matrix<FloatT, 3, 3> > svd(sum, ComputeFullU | ComputeFullV); | ||
|
||
Matrix<FloatT, 3, 3> result = svd.matrixU() | ||
* (Matrix<FloatT, 3, 1>() << 1, 1, svd.matrixU().determinant()*svd.matrixV().determinant()).finished().asDiagonal() | ||
* svd.matrixV().transpose(); | ||
return Quaternion<FloatT>(result); | ||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.