38 #ifndef _ICUB_STEREOVISION_STEREOCAMERA_H_
39 #define _ICUB_STEREOVISION_STEREOCAMERA_H_
47 #include <opencv2/opencv.hpp>
49 #include <iCub/stereoVision/camera.h>
50 #include <iCub/stereoVision/elasWrapper.h>
52 #include <yarp/os/all.h>
60 using namespace yarp::os;
68 using cv::FileStorage;
71 using cv::FeatureDetector;
72 using cv::DescriptorMatcher;
81 using cv::TermCriteria;
138 vector<Point2f> PointsL;
139 vector<Point2f> PointsR;
141 vector<Point2f> InliersL;
142 vector<Point2f> InliersR;
149 bool readStringList(
const string& filename, vector<string>& l );
150 void runStereoCalib(
const vector<string>& imagelist, Size boardSize,
float sqsize);
151 double* reprojectionError(Mat& Rot, Mat& Tras);
152 void crossCheckMatching( cv::BFMatcher &descriptorMatcher,
const Mat& descriptors1,
const Mat& descriptors2, vector<DMatch>& filteredMatches12,
double radius);
153 void updatePMatrix();
154 void stereoCalibration(
string imagesFilePath,
int boardWidth,
int boardHeight,
float sqsize);
155 void normalizePoints(Mat & K1, Mat & K2, vector<Point2f> & PointsL, vector<Point2f> & PointsR);
156 void getRotation(Mat & q, Mat & R);
157 void printMatrix(Mat &matrix);
158 double reprojectionErrorAvg();
159 void savePoints(
string pointsLPath,
string pointsRPath, vector<Point2f> PointL, vector<Point2f> PointR);
161 Mat buildRotTras(Mat & R, Mat & T);
162 void buildUndistortRemap();
163 void printStereoIntrinsic();
164 void printExtrinsic();
165 bool loadStereoParameters(yarp::os::ResourceFinder &rf, Mat &KL, Mat &KR, Mat &DistL, Mat &DistR, Mat &Ro, Mat &T);
166 void updateExpectedCameraMatrices();
171 elasWrapper* elaswrap;
174 int debug_timings[10];
177 cv::Mat right_disp, right_disp16;
197 StereoCamera(yarp::os::ResourceFinder &rf,
bool rectify=
true);
213 void initELAS(yarp::os::ResourceFinder &rf);
223 void stereoCalibration(vector<string> imageList,
int boardWidth,
int boardHeight,
float sqsize=1.0);
231 void saveCalibration(
string extrinsicFilePath,
string intrinsicFilePath);
238 void setImages(
const Mat &firstImg,
const Mat &secondImg);
247 cv::Mat findMatch(
bool visualize=
false,
double displacement=20.0,
double radius=200.0);
256 void computeDisparity(
bool best=
true,
int uniquenessRatio=15,
int speckleWindowSize=50,
int speckleRange=16,
int numberOfDisparities=64,
int SADWindowSize=7,
int minDisparity=0,
int preFilterCap=63,
int disp12MaxDiff=0);
261 void undistortImages();
273 void horn(Mat &K1,Mat &K2, vector<Point2f> &Points1,vector<Point2f> &Points2,Mat &Rot,Mat &Tras);
279 void hornRelativeOrientations();
288 Point3f triangulation(Point2f& point1, Point2f& point2);
299 Point3f triangulation(Point2f& point1, Point2f& point2, Mat Camera1, Mat Camera2);
318 Point3f metricTriangulation(Point2f &point1,
double thMeters=10);
327 Point3f metricTriangulation(Point2f &point1, Mat &H,
double thMeters=10);
338 Point3f triangulateKnownDisparity(
float u,
float v,
float d, Mat &H);
343 void estimateEssential();
348 bool essentialDecomposition();
364 void chierality( Mat& R1, Mat& R2, Mat& t1, Mat& t2, Mat& R, Mat& t, vector<Point2f> points1, vector<Point2f> points2);
370 const Mat& getImLeft()
const;
376 const Mat& getImRight()
const;
382 const Mat& getImLeftUnd()
const;
388 const Mat& getImRightUnd()
const;
394 const Mat& getDisparity()
const;
400 const Mat& getDisparity16()
const;
406 const Mat& getQ()
const;
412 const Mat& getKleft()
const;
418 const Mat& getKright()
const;
424 const Mat& getFundamental()
const;
430 const vector<Point2f>& getMatchLeft()
const;
436 const vector<Point2f>& getMatchRight()
const;
442 const Mat& getTranslation()
const;
448 const Mat& getRotation()
const;
454 const Mat& getMapperL()
const;
460 const Mat& getMapperR()
const;
466 const Mat& getRLrect()
const;
472 const Mat& getRRrect()
const;
482 void setRotation(Mat& Rot,
int mode=0);
492 void setTranslation(Mat& Tras,
int mul=0);
501 void setIntrinsics(Mat& K1, Mat& K2, Mat& Dist1, Mat& Dist2);
507 void rectifyImages();
513 const Mat& getLRectified()
const;
519 const Mat& getRRectified()
const;
528 vector<Point2f> projectPoints3D(
string camera, vector<Point3f> &points3D, Mat &H);
535 Mat computeWorldImage(Mat &H);
541 const Mat& getDistCoeffRight()
const;
547 const Mat& getDistCoeffLeft()
const;
556 Point2f getDistortedPixel(
int u,
int v,
int cam=1);
569 void setMatches(std::vector<cv::Point2f> & pointsL, std::vector<cv::Point2f> & pointsR);
576 void setExpectedPosition(Mat &Rot, Mat &Tran);
584 Mat FfromP(Mat& P1, Mat& P2);
593 Point2f fromRectifiedToOriginal(
int u,
int v,
int camera);
600 cv::Mat remapDisparity(cv::Mat disp);
606 void updateMappings();
The base class defining a simple camera.
The base class defining stereo camera.
Point3f triangulationLS(Point2f &point1, Point2f &point2, Mat Camera1, Mat Camera2)
It performs the least square triangulation (HZ Chap 12.2 Inhomogenous solution).