Subversion Repositories seema-scanner

Rev

Rev 121 | Rev 128 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 121 Rev 123
1
#include "SMCalibrationWorker.h"
1
#include "SMCalibrationWorker.h"
2
#include "SMCalibrationParameters.h"
2
#include "SMCalibrationParameters.h"
3
 
3
 
4
#include "cvtools.h"
4
#include "cvtools.h"
5
 
5
 
6
#include <QSettings>
6
#include <QSettings>
7
 
7
 
8
void SMCalibrationWorker::performCalibration(std::vector<SMCalibrationSet> calibrationData){
8
void SMCalibrationWorker::performCalibration(std::vector<SMCalibrationSet> calibrationData){
9
 
9
 
10
    QSettings settings;
10
    QSettings settings;
11
 
11
 
12
    // Number of saddle points on calibration pattern
12
    // Number of saddle points on calibration pattern
13
    int checkerCountX = settings.value("calibration/checkerCountX", 22).toInt();
13
    int checkerCountX = settings.value("calibration/checkerCountX", 22).toInt();
14
    int checkerCountY = settings.value("calibration/checkerCountY", 13).toInt();
14
    int checkerCountY = settings.value("calibration/checkerCountY", 13).toInt();
15
    cv::Size checkerCount(checkerCountX, checkerCountY);
15
    cv::Size checkerCount(checkerCountX, checkerCountY);
16
 
16
 
17
    int nSets = calibrationData.size();
17
    int nSets = calibrationData.size();
18
 
18
 
19
    std::vector< std::vector<cv::Point2f> > qc0, qc1;
19
    std::vector< std::vector<cv::Point2f> > qc0, qc1;
20
    std::vector<float> angles;
20
    std::vector<float> angles;
21
 
21
 
22
    // Loop through calibration sets
22
    // Loop through calibration sets
23
    for(int i=0; i<nSets; i++){
23
    for(int i=0; i<nSets; i++){
24
 
24
 
25
        SMCalibrationSet SMCalibrationSetI = calibrationData[i];
25
        SMCalibrationSet SMCalibrationSetI = calibrationData[i];
26
 
26
 
27
        if(!SMCalibrationSetI.checked)
27
        if(!SMCalibrationSetI.checked)
28
            continue;
28
            continue;
29
 
29
 
30
        // Camera 0
30
        // Camera 0
31
        std::vector<cv::Point2f> qci0;
31
        std::vector<cv::Point2f> qci0;
32
        // Convert bayer to grayscale
32
        // Convert bayer to grayscale
33
        cv::Mat temp, gray;
33
        cv::Mat gray;
34
//        SMCalibrationSetI.frame0.convertTo(temp, CV_8UC1, 1.0/256.0);
34
//        SMCalibrationSetI.frame0.convertTo(temp, CV_8UC1, 1.0/256.0);
35
        cv::cvtColor(SMCalibrationSetI.frame0, gray, CV_BayerBG2GRAY);
35
        cv::cvtColor(SMCalibrationSetI.frame0, gray, CV_BayerBG2GRAY);
36
        // Extract checker corners
36
        // Extract checker corners
37
        bool success0 = cv::findChessboardCorners(gray, checkerCount, qci0, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK);
37
        bool success0 = cv::findChessboardCorners(gray, checkerCount, qci0, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK);
38
        if(success0){
38
        if(success0){
39
            cv::cornerSubPix(gray, qci0, cv::Size(5, 5), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 20, 0.001));
39
            cv::cornerSubPix(gray, qci0, cv::Size(5, 5), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 20, 0.001));
40
            // Draw colored chessboard
40
            // Draw colored chessboard
41
            cv::Mat color;
41
            cv::Mat color;
42
            cv::cvtColor(SMCalibrationSetI.frame0, color, CV_BayerBG2RGB);
42
            cv::cvtColor(SMCalibrationSetI.frame0, color, CV_BayerBG2RGB);
43
            cvtools::drawChessboardCorners(color, checkerCount, qci0, success0, 10);
43
            cvtools::drawChessboardCorners(color, checkerCount, qci0, success0, 10);
44
            SMCalibrationSetI.frame0Result = color;
44
            SMCalibrationSetI.frame0Result = color;
45
        }
45
        }
46
 
46
 
47
        emit newFrameResult(i, 0, success0, SMCalibrationSetI.frame0Result);
47
        emit newFrameResult(i, 0, success0, SMCalibrationSetI.frame0Result);
48
 
48
 
49
        // Camera 1
49
        // Camera 1
50
        std::vector<cv::Point2f> qci1;
50
        std::vector<cv::Point2f> qci1;
51
        // Convert bayer to grayscale
51
        // Convert bayer to grayscale
52
//        SMCalibrationSetI.frame1.convertTo(temp, CV_8UC1, 1.0/256.0);
52
//        SMCalibrationSetI.frame1.convertTo(temp, CV_8UC1, 1.0/256.0);
53
        cv::cvtColor(SMCalibrationSetI.frame1, gray, CV_BayerBG2GRAY);
53
        cv::cvtColor(SMCalibrationSetI.frame1, gray, CV_BayerBG2GRAY);
54
        // Extract checker corners
54
        // Extract checker corners
55
        bool success1 = cv::findChessboardCorners(gray, checkerCount, qci1, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK);
55
        bool success1 = cv::findChessboardCorners(gray, checkerCount, qci1, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK);
56
        if(success1){
56
        if(success1){
57
            cv::cornerSubPix(gray, qci1, cv::Size(5, 5), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 20, 0.001));
57
            cv::cornerSubPix(gray, qci1, cv::Size(5, 5), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 20, 0.001));
58
            // Draw colored chessboard
58
            // Draw colored chessboard
59
            cv::Mat color;
59
            cv::Mat color;
60
            cv::cvtColor(SMCalibrationSetI.frame1, color, CV_BayerBG2RGB);
60
            cv::cvtColor(SMCalibrationSetI.frame1, color, CV_BayerBG2RGB);
61
            cvtools::drawChessboardCorners(color, checkerCount, qci1, success1, 10);
61
            cvtools::drawChessboardCorners(color, checkerCount, qci1, success1, 10);
62
            SMCalibrationSetI.frame1Result = color;
62
            SMCalibrationSetI.frame1Result = color;
63
        }
63
        }
64
 
64
 
65
        emit newFrameResult(i, 1, success1, SMCalibrationSetI.frame1Result);
65
        emit newFrameResult(i, 1, success1, SMCalibrationSetI.frame1Result);
66
 
66
 
67
        SMCalibrationSetI.success = success0 && success1;
67
        SMCalibrationSetI.success = success0 && success1;
68
 
68
 
69
        // Add to whole set
69
        // Add to whole set
70
        if(SMCalibrationSetI.success){
70
        if(SMCalibrationSetI.success){
71
            qc0.push_back(qci0);
71
            qc0.push_back(qci0);
72
            qc1.push_back(qci1);
72
            qc1.push_back(qci1);
73
            angles.push_back(SMCalibrationSetI.rotationAngle);
73
            angles.push_back(SMCalibrationSetI.rotationAngle);
74
        }
74
        }
75
 
75
 
76
        // Show progress
76
        // Show progress
77
        emit newSetProcessed(i);
77
        emit newSetProcessed(i);
78
    }
78
    }
79
 
79
 
80
    int nValidSets = qc0.size();
80
    int nValidSets = qc0.size();
81
    if(nValidSets < 2){
81
    if(nValidSets < 2){
82
        std::cerr << "Not enough valid calibration sequences!" << std::endl;
82
        std::cerr << "Not enough valid calibration sequences!" << std::endl;
83
        emit done();
83
        emit done();
84
        return;
84
        return;
85
    }
85
    }
86
 
86
 
87
    // Generate world object coordinates [mm]
87
    // Generate world object coordinates [mm]
88
    float checkerSize = settings.value("calibration/checkerSize", 15.0).toFloat(); // width and height of one field in mm
88
    float checkerSize = settings.value("calibration/checkerSize", 15.0).toFloat(); // width and height of one field in mm
89
    std::vector<cv::Point3f> Qi;
89
    std::vector<cv::Point3f> Qi;
90
    for (int h=0; h<checkerCount.height; h++)
90
    for (int h=0; h<checkerCount.height; h++)
91
        for (int w=0; w<checkerCount.width; w++)
91
        for (int w=0; w<checkerCount.width; w++)
92
            Qi.push_back(cv::Point3f(checkerSize * w, checkerSize* h, 0.0));
92
            Qi.push_back(cv::Point3f(checkerSize * w, checkerSize* h, 0.0));
93
    std::vector< std::vector<cv::Point3f> > Q;
93
    std::vector< std::vector<cv::Point3f> > Q;
94
    for(int i=0; i<qc0.size(); i++)
94
    for(int i=0; i<qc0.size(); i++)
95
        Q.push_back(Qi);
95
        Q.push_back(Qi);
96
 
96
 
97
    // calibrate the cameras
97
    // calibrate the cameras
98
    SMCalibrationParameters cal;
98
    SMCalibrationParameters cal;
99
    cal.frameWidth = calibrationData[0].frame0.cols;
99
    cal.frameWidth = calibrationData[0].frame0.cols;
100
    cal.frameHeight = calibrationData[0].frame0.rows;
100
    cal.frameHeight = calibrationData[0].frame0.rows;
101
    cv::Size frameSize(cal.frameWidth, cal.frameHeight);
101
    cv::Size frameSize(cal.frameWidth, cal.frameHeight);
102
 
102
 
103
    // determine only k1, k2 for lens distortion
103
    // determine only k1, k2 for lens distortion
104
    int flags = cv::CALIB_FIX_K3;
104
    int flags = cv::CALIB_FIX_ASPECT_RATIO + cv::CALIB_FIX_PRINCIPAL_POINT + cv::CALIB_FIX_K3;
105
    // Note: several of the output arguments below must be cv::Mat, otherwise segfault
105
    // Note: several of the output arguments below must be cv::Mat, otherwise segfault
106
    std::vector<cv::Mat> cam_rvecs0, cam_tvecs0;
106
    std::vector<cv::Mat> cam_rvecs0, cam_tvecs0;
107
    cal.cam0_error = cv::calibrateCamera(Q, qc0, frameSize, cal.K0, cal.k0, cam_rvecs0, cam_tvecs0, flags);
107
    cal.cam0_error = cv::calibrateCamera(Q, qc0, frameSize, cal.K0, cal.k0, cam_rvecs0, cam_tvecs0, flags);
108
 
108
 
109
//    // refine extrinsics for camera 0
109
//    // refine extrinsics for camera 0
110
//    for(int i=0; i<Q.size(); i++)
110
//    for(int i=0; i<Q.size(); i++)
111
//        cv::solvePnPRansac(Q[i], qc0[i], cal.K0, cal.k0, cam_rvecs0[i], cam_tvecs0[i], true, 100, 0.05, 100, cv::noArray(), CV_ITERATIVE);
111
//        cv::solvePnPRansac(Q[i], qc0[i], cal.K0, cal.k0, cam_rvecs0[i], cam_tvecs0[i], true, 100, 0.05, 100, cv::noArray(), CV_ITERATIVE);
112
 
112
 
113
    std::vector<cv::Mat> cam_rvecs1, cam_tvecs1;
113
    std::vector<cv::Mat> cam_rvecs1, cam_tvecs1;
114
    cal.cam1_error = cv::calibrateCamera(Q, qc1, frameSize, cal.K1, cal.k1, cam_rvecs1, cam_tvecs1, flags);
114
    cal.cam1_error = cv::calibrateCamera(Q, qc1, frameSize, cal.K1, cal.k1, cam_rvecs1, cam_tvecs1, flags);
115
 
115
 
116
    // stereo calibration
116
    // stereo calibration
117
    int flags_stereo = cv::CALIB_FIX_K3;
117
    int flags_stereo = cv::CALIB_FIX_INTRINSIC;
118
    cv::Mat E, F, R1, T1;
118
    cv::Mat E, F, R1, T1;
119
    cal.stereo_error = cv::stereoCalibrate(Q, qc0, qc1, cal.K0, cal.k0, cal.K1, cal.k1,
119
    cal.stereo_error = cv::stereoCalibrate(Q, qc0, qc1, cal.K0, cal.k0, cal.K1, cal.k1,
120
                                              frameSize, R1, T1, E, F,
120
                                              frameSize, R1, T1, E, F,
121
                                              cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 100, DBL_EPSILON),
121
                                              cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 100, DBL_EPSILON),
122
                                              flags_stereo);
122
                                              flags_stereo);
123
 
123
 
124
    cal.R1 = R1;
124
    cal.R1 = R1;
125
    cal.T1 = T1;
125
    cal.T1 = T1;
126
    cal.E = E;
126
    cal.E = E;
127
    cal.F = F;
127
    cal.F = F;
128
 
128
 
129
//    // hand-eye calibration
129
//    // hand-eye calibration
130
//    std::vector<cv::Matx33f> Rc(nValidSets - 1); // rotations/translations of the checkerboard in camera 0 reference frame
130
//    std::vector<cv::Matx33f> Rc(nValidSets - 1); // rotations/translations of the checkerboard in camera 0 reference frame
131
//    std::vector<cv::Vec3f> Tc(nValidSets - 1);
131
//    std::vector<cv::Vec3f> Tc(nValidSets - 1);
132
//    std::vector<cv::Matx33f> Rr(nValidSets - 1); // in rotation stage reference frame
132
//    std::vector<cv::Matx33f> Rr(nValidSets - 1); // in rotation stage reference frame
133
//    std::vector<cv::Vec3f> Tr(nValidSets - 1);
133
//    std::vector<cv::Vec3f> Tr(nValidSets - 1);
134
//    for(int i=0; i<nValidSets-1; i++){
134
//    for(int i=0; i<nValidSets-1; i++){
135
//        // relative transformations in camera
135
//        // relative transformations in camera
136
//        cv::Mat cRw1, cRw2;
136
//        cv::Mat cRw1, cRw2;
137
//        cv::Rodrigues(cam_rvecs0[i], cRw1);
137
//        cv::Rodrigues(cam_rvecs0[i], cRw1);
138
//        cv::Rodrigues(cam_rvecs0[i+1], cRw2);
138
//        cv::Rodrigues(cam_rvecs0[i+1], cRw2);
139
//        cv::Mat cTw1 = cam_tvecs0[i];
139
//        cv::Mat cTw1 = cam_tvecs0[i];
140
//        cv::Mat cTw2 = cam_tvecs0[i+1];
140
//        cv::Mat cTw2 = cam_tvecs0[i+1];
141
//        cv::Mat w1Rc = cRw1.t();
141
//        cv::Mat w1Rc = cRw1.t();
142
//        cv::Mat w1Tc = -cRw1.t()*cTw1;
142
//        cv::Mat w1Tc = -cRw1.t()*cTw1;
143
//        Rc[i] = cv::Mat(cRw2*w1Rc);
143
//        Rc[i] = cv::Mat(cRw2*w1Rc);
144
//        Tc[i] = cv::Mat(cRw2*w1Tc+cTw2);
144
//        Tc[i] = cv::Mat(cRw2*w1Tc+cTw2);
145
 
145
 
146
//        // relative transformations in rotation stage
146
//        // relative transformations in rotation stage
147
//        // we define the rotation axis to be in origo, pointing in positive y direction
147
//        // we define the rotation axis to be in origo, pointing in positive y direction
148
//        float angleRadians = (angles[i+1]-angles[i])/180.0*M_PI;
148
//        float angleRadians = (angles[i+1]-angles[i])/180.0*M_PI;
149
//        cv::Vec3f rot_rvec(0.0, -angleRadians, 0.0);
149
//        cv::Vec3f rot_rvec(0.0, -angleRadians, 0.0);
150
//        cv::Mat Rri;
150
//        cv::Mat Rri;
151
//        cv::Rodrigues(rot_rvec, Rri);
151
//        cv::Rodrigues(rot_rvec, Rri);
152
//        Rr[i] = Rri;
152
//        Rr[i] = Rri;
153
//        Tr[i] = 0.0;
153
//        Tr[i] = 0.0;
154
 
154
 
155
////        std::cout << i << std::endl;
155
////        std::cout << i << std::endl;
156
////        std::cout << "cTw1" << cTw1 << std::endl;
156
////        std::cout << "cTw1" << cTw1 << std::endl;
157
////        std::cout << "cTw2" << cTw2 << std::endl;
157
////        std::cout << "cTw2" << cTw2 << std::endl;
158
////        std::cout << "w2Rc" << w2Rc << std::endl;
158
////        std::cout << "w2Rc" << w2Rc << std::endl;
159
////        std::cout << "w2Tc" << w2Tc << std::endl;
159
////        std::cout << "w2Tc" << w2Tc << std::endl;
160
 
160
 
161
////        std::cout << "w2Rc" << w2Rc << std::endl;
161
////        std::cout << "w2Rc" << w2Rc << std::endl;
162
////        std::cout << "w2Tc" << w2Tc << std::endl;
162
////        std::cout << "w2Tc" << w2Tc << std::endl;
163
 
163
 
164
////        cv::Mat Rci;
164
////        cv::Mat Rci;
165
////        cv::Rodrigues(Rc[i], Rci);
165
////        cv::Rodrigues(Rc[i], Rci);
166
////        std::cout << "Rci" << Rci << std::endl;
166
////        std::cout << "Rci" << Rci << std::endl;
167
////        std::cout << "Tc[i]" << Tc[i] << std::endl;
167
////        std::cout << "Tc[i]" << Tc[i] << std::endl;
168
 
168
 
169
////        std::cout << "rot_rvec" << rot_rvec << std::endl;
169
////        std::cout << "rot_rvec" << rot_rvec << std::endl;
170
////        std::cout << "Tr[i]" << Tr[i] << std::endl;
170
////        std::cout << "Tr[i]" << Tr[i] << std::endl;
171
////        std::cout << std::endl;
171
////        std::cout << std::endl;
172
//    }
172
//    }
173
 
173
 
174
//    // determine the transformation from rotation stage to camera 0
174
//    // determine the transformation from rotation stage to camera 0
175
//    cvtools::handEyeCalibrationTsai(Rc, Tc, Rr, Tr, cal.Rr, cal.Tr);
175
//    cvtools::handEyeCalibrationTsai(Rc, Tc, Rr, Tr, cal.Rr, cal.Tr);
176
 
176
 
177
//    for(int i=0; i<nValidSets-1; i++){
177
//    for(int i=0; i<nValidSets-1; i++){
178
//        std::cout << i << std::endl;
178
//        std::cout << i << std::endl;
179
 
179
 
180
//        cv::Mat Rci;
180
//        cv::Mat Rci;
181
//        cv::Rodrigues(Rc[i], Rci);
181
//        cv::Rodrigues(Rc[i], Rci);
182
//        std::cout << "Rc[i]" << Rci << std::endl;
182
//        std::cout << "Rc[i]" << Rci << std::endl;
183
//        std::cout << "Tc[i]" << Tc[i] << std::endl;
183
//        std::cout << "Tc[i]" << Tc[i] << std::endl;
184
 
184
 
185
//        cv::Mat Rri;
185
//        cv::Mat Rri;
186
//        cv::Rodrigues(Rr[i], Rri);
186
//        cv::Rodrigues(Rr[i], Rri);
187
//        std::cout << "Rr[i]" << Rri << std::endl;
187
//        std::cout << "Rr[i]" << Rri << std::endl;
188
//        std::cout << "Tr[i]" << Tr[i] << std::endl;
188
//        std::cout << "Tr[i]" << Tr[i] << std::endl;
189
 
189
 
190
//        cv::Mat Rcr = cv::Mat(cal.Rr)*cv::Mat(Rc[i])*cv::Mat(cal.Rr.t());
190
//        cv::Mat Rcr = cv::Mat(cal.Rr)*cv::Mat(Rc[i])*cv::Mat(cal.Rr.t());
191
//        cv::Rodrigues(Rcr, Rcr);
191
//        cv::Rodrigues(Rcr, Rcr);
192
//        cv::Mat Tcr = -cv::Mat(cal.Rr)*cv::Mat(Rc[i])*cv::Mat(cal.Rr.t())*cv::Mat(cal.Tr) + cv::Mat(cal.Rr)*cv::Mat(Tc[i]) + cv::Mat(cal.Tr);
192
//        cv::Mat Tcr = -cv::Mat(cal.Rr)*cv::Mat(Rc[i])*cv::Mat(cal.Rr.t())*cv::Mat(cal.Tr) + cv::Mat(cal.Rr)*cv::Mat(Tc[i]) + cv::Mat(cal.Tr);
193
//        std::cout << "Rcr[i]" << Rcr << std::endl;
193
//        std::cout << "Rcr[i]" << Rcr << std::endl;
194
//        std::cout << "Tcr[i]" << Tcr << std::endl;
194
//        std::cout << "Tcr[i]" << Tcr << std::endl;
195
//        std::cout << std::endl;
195
//        std::cout << std::endl;
196
//    }
196
//    }
197
 
197
 
198
 
198
 
199
    // Direct rotation axis calibration //
199
    // Direct rotation axis calibration //
200
    // full camera matrices
200
    // full camera matrices
201
    cv::Matx34f P0 = cv::Matx34f::eye();
201
    cv::Matx34f P0 = cv::Matx34f::eye();
202
    cv::Mat RT1(3, 4, CV_32F);
202
    cv::Mat RT1(3, 4, CV_32F);
203
    cv::Mat(cal.R1).copyTo(RT1(cv::Range(0, 3), cv::Range(0, 3)));
203
    cv::Mat(cal.R1).copyTo(RT1(cv::Range(0, 3), cv::Range(0, 3)));
204
    cv::Mat(cal.T1).copyTo(RT1(cv::Range(0, 3), cv::Range(3, 4)));
204
    cv::Mat(cal.T1).copyTo(RT1(cv::Range(0, 3), cv::Range(3, 4)));
205
    cv::Matx34f P1 = cv::Matx34f(RT1);
205
    cv::Matx34f P1 = cv::Matx34f(RT1);
206
 
206
 
207
    // calibration points in camera 0 frame
207
    // calibration points in camera 0 frame
208
    std::vector< std::vector<cv::Point3f> > Qcam;
208
    std::vector< std::vector<cv::Point3f> > Qcam;
209
 
209
 
210
    for(int i=0; i<nValidSets; i++){
210
    for(int i=0; i<nValidSets; i++){
211
        std::vector<cv::Point2f> qc0i, qc1i;
211
        std::vector<cv::Point2f> qc0i, qc1i;
212
 
212
 
213
        cv::undistortPoints(qc0[i], qc0i, cal.K0, cal.k0);
213
        cv::undistortPoints(qc0[i], qc0i, cal.K0, cal.k0);
214
        cv::undistortPoints(qc1[i], qc1i, cal.K1, cal.k1);
214
        cv::undistortPoints(qc1[i], qc1i, cal.K1, cal.k1);
215
//        qc0i = qc0[i];
215
//        qc0i = qc0[i];
216
//        qc1i = qc1[i];
216
//        qc1i = qc1[i];
217
 
217
 
218
        cv::Mat Qhom, Qcami;
218
        cv::Mat Qhom, Qcami;
219
        cv::triangulatePoints(P0, P1, qc0i, qc1i, Qhom);
219
        cv::triangulatePoints(P0, P1, qc0i, qc1i, Qhom);
220
        cvtools::convertMatFromHomogeneous(Qhom, Qcami);
220
        cvtools::convertMatFromHomogeneous(Qhom, Qcami);
221
        std::vector<cv::Point3f> QcamiPoints;
221
        std::vector<cv::Point3f> QcamiPoints;
222
        cvtools::matToPoints3f(Qcami, QcamiPoints);
222
        cvtools::matToPoints3f(Qcami, QcamiPoints);
223
 
223
 
224
        Qcam.push_back(QcamiPoints);
224
        Qcam.push_back(QcamiPoints);
225
    }
225
    }
226
 
226
 
227
    cv::Vec3f axis, point;
227
    cv::Vec3f axis, point;
228
    cvtools::rotationAxisCalibration(Qcam, Qi, axis, point);
228
    cvtools::rotationAxisCalibration(Qcam, Qi, axis, point);
229
 
229
 
230
    // construct transformation matrix
230
    // construct transformation matrix
231
    cv::Vec3f ex = axis.cross(cv::Vec3f(0,0,1.0));
231
    cv::Vec3f ex = axis.cross(cv::Vec3f(0,0,1.0));
232
    ex = cv::normalize(ex);
232
    ex = cv::normalize(ex);
233
    cv::Vec3f ez = ex.cross(axis);
233
    cv::Vec3f ez = ex.cross(axis);
234
    ez = cv::normalize(ez);
234
    ez = cv::normalize(ez);
235
 
235
 
236
    cv::Mat RrMat(3, 3, CV_32F);
236
    cv::Mat RrMat(3, 3, CV_32F);
237
    cv::Mat(ex).copyTo(RrMat.col(0));
237
    cv::Mat(ex).copyTo(RrMat.col(0));
238
    cv::Mat(axis).copyTo(RrMat.col(1));
238
    cv::Mat(axis).copyTo(RrMat.col(1));
239
    cv::Mat(ez).copyTo(RrMat.col(2));
239
    cv::Mat(ez).copyTo(RrMat.col(2));
240
 
240
 
241
    cal.Rr = cv::Matx33f(RrMat).t();
241
    cal.Rr = cv::Matx33f(RrMat).t();
242
    cal.Tr = -cv::Matx33f(RrMat).t()*point;
242
    cal.Tr = -cv::Matx33f(RrMat).t()*point;
243
 
243
 
244
    // Print to std::cout
244
    // Print to std::cout
245
    cal.print();
245
    cal.print();
246
 
246
 
247
    // save to (reentrant qsettings object)
247
    // save to (reentrant qsettings object)
248
    settings.setValue("calibration/parameters", QVariant::fromValue(cal));
248
    settings.setValue("calibration/parameters", QVariant::fromValue(cal));
249
 
249
 
250
    emit done();
250
    emit done();
251
 
251
 
252
}
252
}
253
 
253