iCub-main
Loading...
Searching...
No Matches
stereoCalibThread.h
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <string>
4#include <mutex>
5
6#include <opencv2/calib3d/calib3d_c.h>
7#include <opencv2/calib3d.hpp>
8#include <opencv2/core/core_c.h>
9#include <opencv2/core/types_c.h>
10#include <opencv2/imgcodecs.hpp>
11
12
13
14#include <yarp/os/all.h>
15#include <yarp/dev/all.h>
16#include <yarp/sig/all.h>
17#include <yarp/math/Math.h>
18
19#include <iCub/iKin/iKinFwd.h>
20
21using namespace std;
22using namespace cv;
23using namespace yarp::os;
24using namespace yarp::dev;
25using namespace yarp::sig;
26using namespace yarp::math;
27using namespace iCub::iKin;
28
29
30#define LEFT 0
31#define RIGHT 1
32
33class stereoCalibThread : public Thread
34{
35private:
36
37 ImageOf<PixelRgb> *imageL;
38 ImageOf<PixelRgb> *imageR;
39 Mat Left;
40 Mat Right;
41
42 string moduleName;
43 string robotName;
44 yarp::sig::Vector qL;
45 yarp::sig::Vector qR;
46
47 mutex mtx;
48
49 int numOfPairs;
50 bool stereo;
51 Mat Kleft;
52 Mat Kright;
53
54 Mat DistL;
55 Mat DistR;
56 double vergence;
57 double version;
58
59 bool standalone;
60 yarp::dev::PolyDriver polyHead;
61 yarp::dev::IEncoders *posHead;
62
63 yarp::dev::PolyDriver polyTorso;
64 yarp::dev::IEncoders *posTorso;
65
66 Mat R;
67 Mat T;
68 Mat Q;
69 string inputLeftPortName;
70 string inputRightPortName;
71 string outNameRight;
72 string outNameLeft;
73 string camCalibFile;
74 string currentPathDir;
75 std::vector<string> imageListR;
76 std::vector<string> imageListL;
77 std::vector<string> imageListLR;
78
79 BufferedPort<ImageOf<PixelRgb> > imagePortInLeft;
80 BufferedPort<ImageOf<PixelRgb> > imagePortInRight;
81 BufferedPort<ImageOf<PixelRgb> > outPortRight;
82 BufferedPort<ImageOf<PixelRgb> > outPortLeft;
83
84 Port *commandPort;
85 string imageDir;
86 int startCalibration;
87 int boardWidth;
88 int boardHeight;
89 float squareSize;
90 string boardType;
91 char pathL[256];
92 char pathR[256];
93 void printMatrix(Mat &matrix);
94 bool checkTS(double TSLeft, double TSRight, double th=0.08);
95 void preparePath(const char * imageDir, char* pathL, char* pathR, int num);
96 void saveStereoImage(const char * imageDir, const Mat& left, const Mat& right, int num);
97 void monoCalibration(const vector<string>& imageList, int boardWidth, int boardHeight, Mat &K, Mat &Dist);
98 void stereoCalibration(const vector<string>& imagelist, int boardWidth, int boardHeight,float sqsizee);
99 void saveCalibration(const string& extrinsicFilePath, const string& intrinsicFilePath);
100 void calcChessboardCorners(Size boardSize, float squareSize, vector<Point3f>& corners);
101 bool updateIntrinsics( int width, int height, double fx, double fy,double cx, double cy, double k1, double k2, double p1, double p2, const string& groupname);
102 bool updateExtrinsics(Mat Rot, Mat Tr, const string& groupname);
103 void saveImage(const char * imageDir, const Mat& left, int num);
104 void stereoCalibRun();
105 void monoCalibRun();
106
107public:
108
109
110 stereoCalibThread(ResourceFinder &rf, Port* commPort, const char *imageDir);
111 void startCalib();
112 void stopCalib();
113 bool threadInit();
114 void threadRelease();
115 void run();
116 void onStop();
117
118};
119
120