Subversion Repositories seema-scanner

Rev

Rev 207 | Rev 228 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jakw 1
#include "SMCalibrationWorker.h"
2
#include "SMCalibrationParameters.h"
22 jakw 3
 
31 jakw 4
#include "cvtools.h"
5
 
22 jakw 6
#include <QSettings>
225 jakw 7
#include <QTextStream>
22 jakw 8
 
196 jakw 9
#include <ceres/ceres.h>
10
 
11
// Closed form solution to solve for the rotation axis from sets of 3D point coordinates of flat pattern feature points
12
// Algorithm according to Chen et al., Rotation axis calibration of a turntable using constrained global optimization, Optik 2014
13
// DTU, 2014, Jakob Wilm
225 jakw 14
static void rotationAxisEstimation(const std::vector< std::vector<cv::Point3f> > Qcam,
15
                                   const std::vector<cv::Point3f> Qobj,
16
                                   cv::Vec3f &axis, cv::Vec3f &point){
207 flgw 17
    assert(Qobj.size() == Qcam[0].size());
196 jakw 18
 
19
    // number of frames (points on each arch)
20
    int l = Qcam.size();
21
 
22
    // number of points in each frame
23
    size_t mn = Qobj.size();
24
 
25
    // construct matrix for axis determination
26
    cv::Mat M(6, 6, CV_32F, cv::Scalar(0));
27
 
28
    for(int k=0; k<l; k++){
29
        for(unsigned int idx=0; idx<mn; idx++){
30
 
207 flgw 31
            //            float i = Qobj[idx].x+4;
32
            //            float j = Qobj[idx].y+4;
196 jakw 33
            float i = Qobj[idx].x;
34
            float j = Qobj[idx].y;
35
 
36
            float x = Qcam[k][idx].x;
37
            float y = Qcam[k][idx].y;
38
            float z = Qcam[k][idx].z;
39
 
40
            M += (cv::Mat_<float>(6,6) << x*x, x*y, x*z, x, i*x, j*x,
207 flgw 41
                  0, y*y, y*z, y, i*y, j*y,
42
                  0,   0, z*z, z, i*z, j*z,
43
                  0,   0,   0, 1,   i,   j,
44
                  0,   0,   0, 0, i*i, i*j,
45
                  0,   0,   0, 0,   0, j*j);
196 jakw 46
 
47
        }
48
    }
49
 
50
    cv::completeSymm(M, false);
51
 
52
    // solve for axis
53
    std::vector<float> lambda;
54
    cv::Mat u;
55
    cv::eigen(M, lambda, u);
56
 
57
    float minLambda = std::abs(lambda[0]);
58
    int idx = 0;
59
    for(unsigned int i=1; i<lambda.size(); i++){
60
        if(abs(lambda[i]) < minLambda){
61
            minLambda = lambda[i];
62
            idx = i;
63
        }
64
    }
65
 
66
    axis = u.row(idx).colRange(0, 3);
67
    axis = cv::normalize(axis);
68
 
69
    float nx = u.at<float>(idx, 0);
70
    float ny = u.at<float>(idx, 1);
71
    float nz = u.at<float>(idx, 2);
72
    //float d  = u.at<float>(idx, 3);
73
    float dh = u.at<float>(idx, 4);
74
    float dv = u.at<float>(idx, 5);
75
 
207 flgw 76
    // Paper version: c is initially eliminated
77
    /*cv::Mat A(l*mn, mn+2, CV_32F, cv::Scalar(0.0));
78
        cv::Mat bb(l*mn, 1, CV_32F);
196 jakw 79
 
207 flgw 80
        for(int k=0; k<l; k++){
81
            for(unsigned int idx=0; idx<mn; idx++){
196 jakw 82
 
207 flgw 83
                float i = Qobj[idx].x;
84
                float j = Qobj[idx].y;
196 jakw 85
 
207 flgw 86
                float x = Qcam[k][idx].x;
87
                float y = Qcam[k][idx].y;
88
                float z = Qcam[k][idx].z;
196 jakw 89
 
207 flgw 90
                float f = x*x + y*y + z*z + (2*x*nx + 2*y*ny + 2*z*nz)*(i*dh + j*dv);
196 jakw 91
 
207 flgw 92
                int row = k*mn+idx;
93
                A.at<float>(row, 0) = 2*x - (2*z*nx)/nz;
94
                A.at<float>(row, 1) = 2*y - (2*z*ny)/nz;
95
                A.at<float>(row, idx+2) = 1.0;
196 jakw 96
 
207 flgw 97
                bb.at<float>(row, 0) = f + (2*z*d)/nz;
98
            }
99
        }
196 jakw 100
 
207 flgw 101
        // solve for point
102
        cv::Mat abe;
103
        cv::solve(A, bb, abe, cv::DECOMP_SVD);
196 jakw 104
 
207 flgw 105
        float a = abe.at<float>(0, 0);
106
        float b = abe.at<float>(1, 0);
107
        float c = -(nx*a+ny*b+d)/nz;
108
        */
196 jakw 109
 
110
    // Our version: solve simultanously for a,b,c
111
    cv::Mat A(l*mn, mn+3, CV_32F, cv::Scalar(0.0));
112
    cv::Mat bb(l*mn, 1, CV_32F);
113
 
114
    for(int k=0; k<l; k++){
115
        for(unsigned int idx=0; idx<mn; idx++){
116
 
117
            float i = Qobj[idx].x;
118
            float j = Qobj[idx].y;
119
 
120
            float x = Qcam[k][idx].x;
121
            float y = Qcam[k][idx].y;
122
            float z = Qcam[k][idx].z;
123
 
124
            float f = x*x + y*y + z*z + (2*x*nx + 2*y*ny + 2*z*nz)*(i*dh + j*dv);
125
 
126
            int row = k*mn+idx;
127
            A.at<float>(row, 0) = 2*x;
128
            A.at<float>(row, 1) = 2*y;
129
            A.at<float>(row, 2) = 2*z;
130
            A.at<float>(row, idx+3) = 1.0;
131
 
132
            bb.at<float>(row, 0) = f;
133
        }
134
    }
135
 
136
    // solve for point
137
    cv::Mat abe;
138
    cv::solve(A, bb, abe, cv::DECOMP_SVD);
139
 
140
    float a = abe.at<float>(0, 0);
141
    float b = abe.at<float>(1, 0);
142
    float c = abe.at<float>(2, 0);
143
 
144
    point[0] = a;
145
    point[1] = b;
146
    point[2] = c;
147
 
225 jakw 148
}
149
 
150
struct CircleResidual {
151
    CircleResidual(std::vector<cv::Point3f> _pointsOnArc)
152
        : pointsOnArc(_pointsOnArc) {}
153
 
154
    template <typename T>
155
    bool operator()(const T* point, const T* axis, T* residual) const {
156
 
157
        T axisSqNorm = axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2];
158
 
159
        unsigned int l = pointsOnArc.size();
160
        std::vector<T> dI(l);
161
 
162
        // note, this is automatically initialized to 0
163
        T sum(0.0);
164
 
165
        for(unsigned int i=0; i<l; i++){
166
            cv::Point3d p = pointsOnArc[i];
167
            //T p[3] = {pointsOnArc[i].x, pointsOnArc[i].y, pointsOnArc[i].z};
168
 
169
            // point to line distance
170
            T dotProd = (point[0]-p.x)*axis[0] + (point[1]-p.y)*axis[1] + (point[2]-p.z)*axis[2];
171
            T dIx = point[0] - p.x - (dotProd*axis[0]/axisSqNorm);
172
            T dIy = point[1] - p.y - (dotProd*axis[1]/axisSqNorm);
173
            T dIz = point[2] - p.z - (dotProd*axis[2]/axisSqNorm);
174
            dI[i] = ceres::sqrt(dIx*dIx + dIy*dIy + dIz*dIz);
175
 
176
            sum += dI[i];
177
        }
178
 
179
        T mean = sum / double(l);
180
 
181
        for(unsigned int i=0; i<l; i++){
182
            residual[i] = dI[i] - mean;
183
        }
184
 
185
        return true;
186
    }
187
 
188
    private:
189
        // Observations for one checkerboard corner.
190
        const std::vector<cv::Point3f> pointsOnArc;
191
};
192
 
193
static void rotationAxisOptimization(const std::vector< std::vector<cv::Point3f> > Qcam, const std::vector<cv::Point3f> Qobj, cv::Vec3f &axis, cv::Vec3f &point, float &error){
194
 
195
    // number of frames (points on each arch)
196
    size_t l = Qcam.size();
197
 
198
    // number of points in each frame
199
    size_t mn = Qobj.size();
200
 
201
    // read initial guess
197 jakw 202
    double pointArray[] = {point[0], point[1], point[2]};
203
    double axisArray[] = {axis[0], axis[1], axis[2]};
196 jakw 204
 
205
    ceres::Problem problem;
225 jakw 206
 
196 jakw 207
    // loop through saddle points
208
    for(unsigned int idx=0; idx<mn; idx++){
209
        std::vector<cv::Point3f> pointsOnArch(l);
225 jakw 210
        for(unsigned int k=0; k<l; k++){
196 jakw 211
            pointsOnArch[k] = Qcam[k][idx];
212
        }
213
        ceres::CostFunction* cost_function =
207 flgw 214
                new ceres::AutoDiffCostFunction<CircleResidual, ceres::DYNAMIC, 3, 3>(
215
                    new CircleResidual(pointsOnArch), l);
197 jakw 216
        problem.AddResidualBlock(cost_function, NULL, pointArray, axisArray);
196 jakw 217
    }
218
 
219
    // Run the solver!
220
    ceres::Solver::Options options;
221
    options.linear_solver_type = ceres::DENSE_QR;
222
    options.minimizer_progress_to_stdout = true;
223
    ceres::Solver::Summary summary;
224
    ceres::Solve(options, &problem, &summary);
225
 
226
    std::cout << summary.BriefReport() << "\n";
227
 
197 jakw 228
    point = cv::Vec3f(pointArray[0], pointArray[1], pointArray[2]);
229
    axis = cv::Vec3f(axisArray[0], axisArray[1], axisArray[2]);
230
    axis /= cv::norm(axis);
196 jakw 231
 
232
 
197 jakw 233
    // Error estimate (sum of squared differences)
196 jakw 234
    error = 0;
235
    // loop through saddle points
236
    for(unsigned int idx=0; idx<mn; idx++){
237
 
238
        // vector of distances from rotation axis
239
        std::vector<float> dI(l);
240
        // loop through angular positions
225 jakw 241
        for(unsigned int k=0; k<l; k++){
196 jakw 242
            cv::Vec3f p = cv::Vec3f(Qcam[k][idx]);
243
            // point to line distance
244
            dI[k] = cv::norm((point-p)-(point-p).dot(axis)*axis);
245
        }
246
        float sum = std::accumulate(dI.begin(), dI.end(), 0.0);
247
        float mean = sum / dI.size();
198 jakw 248
        float meanDev = 0;
225 jakw 249
        for(unsigned int k=0; k<l; k++){
198 jakw 250
            meanDev += std::abs(dI[k] - mean);
196 jakw 251
        }
198 jakw 252
        meanDev /= l;
253
        error += meanDev;
196 jakw 254
    }
198 jakw 255
    error /= mn;
196 jakw 256
}
257
 
225 jakw 258
static std::vector<cv::Point3f> generateWorldCoords(const cv::Size checkerCount, const float checkerSize){
259
 
260
    std::vector<cv::Point3f> Qi;
261
    for (int h=0; h<checkerCount.height; h++)
262
        for (int w=0; w<checkerCount.width; w++)
263
            Qi.push_back(cv::Point3f(checkerSize * w, checkerSize* h, 0.0));
264
 
265
    return Qi;
266
}
267
 
268
static bool detectCheckerBoardCorners(const cv::Size & checkerCount,
269
                                    const cv::Mat & frame,
270
                                    cv::Mat & frameResult,
271
                                    std::vector<cv::Point2f> & qc){
206 flgw 272
    // Convert to grayscale
273
    cv::Mat gray;
225 jakw 274
    if(frame.channels() == 1)
275
        cv::cvtColor(frame, gray, CV_BayerBG2GRAY);
206 flgw 276
    else
225 jakw 277
        cv::cvtColor(frame, gray, CV_RGB2GRAY);
206 flgw 278
 
279
    // Extract checker corners
225 jakw 280
    bool success = cv::findChessboardCorners(gray, checkerCount, qc, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK);
206 flgw 281
    if(success){
225 jakw 282
        cv::cornerSubPix(gray, qc, cv::Size(6, 6), cv::Size(1, 1), cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 20, 0.0001));
206 flgw 283
        // Draw colored chessboard
225 jakw 284
        if(frame.channels() == 1)
285
            cv::cvtColor(frame, frameResult, CV_BayerBG2RGB);
206 flgw 286
        else
225 jakw 287
            frameResult = frame.clone();
206 flgw 288
 
225 jakw 289
        cvtools::drawChessboardCorners(frameResult, checkerCount, qc, success, 10);
206 flgw 290
    }
291
    return success;
292
}
293
 
225 jakw 294
void SMCalibrationWorker::checkerboardDetection(SMCalibrationSet calibrationSet){
22 jakw 295
 
207 flgw 296
    QSettings settings;
225 jakw 297
    cv::Size checkerCount(cv::Size(settings.value("calibration/patternSizeX", 22).toInt(), settings.value("calibration/patternSizeY", 13).toInt()));
22 jakw 298
 
225 jakw 299
    bool success0 = detectCheckerBoardCorners(checkerCount, calibrationSet.frame0, calibrationSet.frame0Result, calibrationSet.qc0);
300
    if(!success0)
301
        emit logMessage(QString("Could not detect checkerboard on set %1 camera0").arg(calibrationSet.id));
22 jakw 302
 
225 jakw 303
    bool success1 = detectCheckerBoardCorners(checkerCount, calibrationSet.frame1, calibrationSet.frame1Result, calibrationSet.qc1);
304
    if(!success1)
305
        emit logMessage(QString("Could not detect checkerboard on set %1 camera1").arg(calibrationSet.id));
25 jakw 306
 
225 jakw 307
    emit newCheckerboardResult(calibrationSet.id, calibrationSet);
25 jakw 308
 
207 flgw 309
}
25 jakw 310
 
225 jakw 311
void SMCalibrationWorker::cameraCalibration(std::vector<SMCalibrationSet> calibrationData){
137 jakw 312
 
225 jakw 313
    QSettings settings;
314
    cv::Size checkerCount(cv::Size(settings.value("calibration/patternSizeX", 22).toInt(), settings.value("calibration/patternSizeY", 13).toInt()));
22 jakw 315
 
225 jakw 316
    unsigned int nSets = calibrationData.size();
22 jakw 317
 
225 jakw 318
    // 2D Points collected for OpenCV's calibration procedures
319
    std::vector< std::vector<cv::Point2f> > qc0, qc1, qc0Stereo, qc1Stereo;
207 flgw 320
 
225 jakw 321
    for(int i=0; i<nSets; i++){
207 flgw 322
 
225 jakw 323
        if(!calibrationData[i].selected)
324
            continue;
207 flgw 325
 
225 jakw 326
        // Note: avoiding push_back has only minor theoretical value
327
        if(!calibrationData[i].qc0.empty())
328
            qc0.push_back(calibrationData[i].qc0);
207 flgw 329
 
225 jakw 330
        if(!calibrationData[i].qc1.empty())
331
            qc1.push_back(calibrationData[i].qc1);
207 flgw 332
 
225 jakw 333
        if(!calibrationData[i].qc0.empty() && !calibrationData[i].qc1.empty()){
334
            qc0Stereo.push_back(calibrationData[i].qc0);
335
            qc1Stereo.push_back(calibrationData[i].qc1);
207 flgw 336
        }
22 jakw 337
    }
338
 
339
    // Generate world object coordinates [mm]
225 jakw 340
    std::vector<cv::Point3f> Qi = generateWorldCoords(checkerCount, settings.value("calibration/squareSize", 10.0).toFloat());
137 jakw 341
 
225 jakw 342
    std::vector< std::vector<cv::Point3f> > Q0(qc0.size(), Qi), Q1(qc1.size(), Qi), QStereo(qc0Stereo.size(), Qi);
22 jakw 343
 
225 jakw 344
    // Calibrate the cameras
31 jakw 345
    SMCalibrationParameters cal;
346
    cal.frameWidth = calibrationData[0].frame0.cols;
347
    cal.frameHeight = calibrationData[0].frame0.rows;
348
    cv::Size frameSize(cal.frameWidth, cal.frameHeight);
22 jakw 349
 
68 jakw 350
    // determine only k1, k2 for lens distortion
140 jakw 351
    int flags = cv::CALIB_FIX_ASPECT_RATIO + cv::CALIB_FIX_K3 + cv::CALIB_ZERO_TANGENT_DIST + cv::CALIB_FIX_PRINCIPAL_POINT;
225 jakw 352
 
33 jakw 353
    std::vector<cv::Mat> cam_rvecs0, cam_tvecs0;
225 jakw 354
 
355
    cal.cam0_error = cv::calibrateCamera(Q0, qc0, frameSize, cal.K0, cal.k0, cam_rvecs0, cam_tvecs0, cal.cam0_intrinsic_std, cal.cam0_extrinsic_std, cal.cam0_errors_per_view, flags,
134 jakw 356
                                         cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 100, DBL_EPSILON));
86 jakw 357
 
33 jakw 358
    std::vector<cv::Mat> cam_rvecs1, cam_tvecs1;
225 jakw 359
    cal.cam1_error = cv::calibrateCamera(Q1, qc1, frameSize, cal.K1, cal.k1, cam_rvecs1, cam_tvecs1, cal.cam1_intrinsic_std, cal.cam1_extrinsic_std, cal.cam1_errors_per_view, flags,
134 jakw 360
                                         cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 100, DBL_EPSILON));
225 jakw 361
 
362
    // Stereo calibration
136 jakw 363
    int flags_stereo = cv::CALIB_FIX_INTRINSIC;// + cv::CALIB_FIX_K2 + cv::CALIB_FIX_K3 + cv::CALIB_ZERO_TANGENT_DIST + cv::CALIB_FIX_PRINCIPAL_POINT + cv::CALIB_FIX_ASPECT_RATIO;
33 jakw 364
    cv::Mat E, F, R1, T1;
22 jakw 365
 
225 jakw 366
    #if CV_MAJOR_VERSION < 3
207 flgw 367
        cal.stereo_error = cv::stereoCalibrate(QStereo, qc0Stereo, qc1Stereo, cal.K0, cal.k0, cal.K1, cal.k1,
368
                                               frameSize, R1, T1, E, F,
369
                                               cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 200, DBL_EPSILON),
370
                                               flags_stereo);
225 jakw 371
    #else
207 flgw 372
        cal.stereo_error = cv::stereoCalibrate(QStereo, qc0Stereo, qc1Stereo, cal.K0, cal.k0, cal.K1, cal.k1,
225 jakw 373
                                               frameSize, R1, T1, E, F, flags_stereo,
207 flgw 374
                                               cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 200, DBL_EPSILON));
225 jakw 375
    #endif
207 flgw 376
 
33 jakw 377
    cal.R1 = R1;
378
    cal.T1 = T1;
379
    cal.E = E;
380
    cal.F = F;
381
 
225 jakw 382
    // Print to log
383
    std::stringstream out;
384
    out << "## Camera Calibration ##" << std::endl
385
        << "No. images used for intrinsics of cam0: " << qc0.size() << std::endl
386
        << "No. images used for intrinsics of cam1: " << qc1.size() << std::endl
387
        << "No. images used for stereo calibration: " << qc0Stereo.size() << std::endl;
388
    cal.printCamera(out);
389
    out << std::endl << std::endl;
390
    emit logMessage(QString::fromStdString(out.str()));
148 jakw 391
 
225 jakw 392
    // save to (reentrant) qsettings object
393
    settings.setValue("calibration/parameters", QVariant::fromValue(cal));
31 jakw 394
 
225 jakw 395
    emit done();
396
}
33 jakw 397
 
91 jakw 398
 
225 jakw 399
void SMCalibrationWorker::rotationStageCalibration(std::vector<SMCalibrationSet> calibrationData){
91 jakw 400
 
225 jakw 401
    int nSets = calibrationData.size();
91 jakw 402
 
225 jakw 403
    std::vector< std::vector<cv::Point2f> > qc0Stereo, qc1Stereo;
404
    for(int i=0; i<nSets; i++){
91 jakw 405
 
225 jakw 406
        if(!calibrationData[i].selected)
407
            continue;
91 jakw 408
 
225 jakw 409
        // Note: avoiding push_back has only minor theoretical value
410
        if(!calibrationData[i].qc0.empty() && !calibrationData[i].qc1.empty()){
411
            qc0Stereo.push_back(calibrationData[i].qc0);
412
            qc1Stereo.push_back(calibrationData[i].qc1);
413
        }
414
    }
33 jakw 415
 
225 jakw 416
    QSettings settings;
417
    SMCalibrationParameters cal = settings.value("calibration/parameters").value<SMCalibrationParameters>();
81 jakw 418
 
225 jakw 419
    if(qc0Stereo.size() > 2){
207 flgw 420
        // Generate world object coordinates [mm]
225 jakw 421
        const cv::Size checkerCount(cv::Size(settings.value("calibration/patternSizeX", 22).toInt(),settings.value("calibration/patternSizeY", 13).toInt()));
422
        const float checkerSize = settings.value("calibration/squareSize", 10.0).toFloat();
423
        std::vector<cv::Point3f> Qi = generateWorldCoords(checkerCount, checkerSize);
91 jakw 424
 
207 flgw 425
        // Direct rotation axis calibration //
426
        // full camera matrices
427
        cv::Matx34f P0 = cv::Matx34f::eye();
428
        cv::Mat RT1(3, 4, CV_32F);
429
        cv::Mat(cal.R1).copyTo(RT1(cv::Range(0, 3), cv::Range(0, 3)));
430
        cv::Mat(cal.T1).copyTo(RT1(cv::Range(0, 3), cv::Range(3, 4)));
431
        cv::Matx34f P1 = cv::Matx34f(RT1);
81 jakw 432
 
207 flgw 433
        // calibration points in camera 0 frame
434
        std::vector< std::vector<cv::Point3f> > Qcam(qc0Stereo.size());
225 jakw 435
 
436
        #pragma omp parallel for
207 flgw 437
        for(unsigned int i=0; i<qc0Stereo.size(); i++){
438
            std::vector<cv::Point2f> qc0i, qc1i;
81 jakw 439
 
207 flgw 440
            cv::undistortPoints(qc0Stereo[i], qc0i, cal.K0, cal.k0);
441
            cv::undistortPoints(qc1Stereo[i], qc1i, cal.K1, cal.k1);
81 jakw 442
 
207 flgw 443
            cv::Mat Qhom, Qcami;
444
            cv::triangulatePoints(P0, P1, qc0i, qc1i, Qhom);
445
            cvtools::convertMatFromHomogeneous(Qhom, Qcami);
446
            std::vector<cv::Point3f> QcamiPoints;
447
            cvtools::matToPoints3f(Qcami, QcamiPoints);
33 jakw 448
 
207 flgw 449
            Qcam[i] = QcamiPoints;
450
        }
81 jakw 451
 
207 flgw 452
        cv::Vec3f axis, point;
453
        float rot_axis_error;
225 jakw 454
        rotationAxisEstimation(Qcam, Qi, axis, point);
455
        rotationAxisOptimization(Qcam, Qi, axis, point, rot_axis_error);
84 jakw 456
 
207 flgw 457
        // construct transformation matrix
458
        cv::Vec3f ex = axis.cross(cv::Vec3f(0,0,1.0));
459
        ex = cv::normalize(ex);
460
        cv::Vec3f ez = ex.cross(axis);
461
        ez = cv::normalize(ez);
84 jakw 462
 
207 flgw 463
        cv::Mat RrMat(3, 3, CV_32F);
464
        cv::Mat(ex).copyTo(RrMat.col(0));
465
        cv::Mat(axis).copyTo(RrMat.col(1));
466
        cv::Mat(ez).copyTo(RrMat.col(2));
467
 
468
        cal.Rr = cv::Matx33f(RrMat).t();
469
        cal.Tr = -cv::Matx33f(RrMat).t()*point;
470
        cal.rot_axis_error = rot_axis_error;
225 jakw 471
    } else {
207 flgw 472
        cal.Rr = cv::Matx33f::eye();
473
        cal.Tr = cv::Vec3f(0,0,0);
474
        cal.rot_axis_error = -1;
225 jakw 475
        return;
91 jakw 476
    }
225 jakw 477
 
478
    // Print to log
479
    std::stringstream out;
480
    out << "## Rotation Stage Calibration ##" << std::endl
481
        << "No. images used for calibration: " << qc0Stereo.size() << std::endl;
482
    cal.printRotationStage(out);
483
    out << std::endl << std::endl;
484
    emit logMessage(QString::fromStdString(out.str()));
485
 
486
    // Save to (reentrant) qsettings object
487
    settings.setValue("calibration/parameters", QVariant::fromValue(cal));
488
 
489
    emit done();
22 jakw 490
}