Subversion Repositories seema-scanner

Rev

Rev 166 | Rev 169 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 166 Rev 167
Line 12... Line 12...
12
    // Number of saddle points on calibration pattern
12
    // Number of saddle points on calibration pattern
13
    int checkerCountX = settings.value("calibration/patternSizeX", 12).toInt();
13
    int checkerCountX = settings.value("calibration/patternSizeX", 12).toInt();
14
    int checkerCountY = settings.value("calibration/patternSizeY", 11).toInt();
14
    int checkerCountY = settings.value("calibration/patternSizeY", 11).toInt();
15
    cv::Size checkerCount(checkerCountX, checkerCountY);
15
    cv::Size checkerCount(checkerCountX, checkerCountY);
16
 
16
 
17
    int nSets = calibrationData.size();
17
    unsigned int nSets = calibrationData.size();
18
 
18
 
19
    // 2D Points collected for OpenCV's calibration procedures
19
    // 2D Points collected for OpenCV's calibration procedures
20
    std::vector< std::vector<cv::Point2f> > qc0, qc1;
20
    std::vector< std::vector<cv::Point2f> > qc0, qc1;
21
    std::vector< std::vector<cv::Point2f> > qc0Stereo, qc1Stereo;
21
    std::vector< std::vector<cv::Point2f> > qc0Stereo, qc1Stereo;
22
 
22
 
23
    std::vector<bool> success0(nSets), success1(nSets);
23
    std::vector<bool> success0(nSets), success1(nSets);
24
 
24
 
25
    std::vector<float> angles;
25
    std::vector<float> angles;
26
 
26
 
27
    // Loop through calibration sets
27
    // Loop through calibration sets
28
    for(int i=0; i<nSets; i++){
28
    for(unsigned int i=0; i<nSets; i++){
29
 
29
 
30
        SMCalibrationSet SMCalibrationSetI = calibrationData[i];
30
        SMCalibrationSet SMCalibrationSetI = calibrationData[i];
31
 
31
 
32
        if(!SMCalibrationSetI.checked)
32
        if(!SMCalibrationSetI.checked)
33
            continue;
33
            continue;
Line 99... Line 99...
99
 
99
 
100
        // Show progress
100
        // Show progress
101
        emit newSetProcessed(i);
101
        emit newSetProcessed(i);
102
    }
102
    }
103
 
103
 
104
    int nValidSets = angles.size();
104
    size_t nValidSets = angles.size();
105
    if(nValidSets < 2){
105
    if(nValidSets < 2){
106
        std::cerr << "Not enough valid calibration sequences!" << std::endl;
106
        std::cerr << "Not enough valid calibration sequences!" << std::endl;
107
        emit done();
107
        emit done();
108
        return;
108
        return;
109
    }
109
    }
Line 114... Line 114...
114
    for (int h=0; h<checkerCount.height; h++)
114
    for (int h=0; h<checkerCount.height; h++)
115
        for (int w=0; w<checkerCount.width; w++)
115
        for (int w=0; w<checkerCount.width; w++)
116
            Qi.push_back(cv::Point3f(checkerSize * w, checkerSize* h, 0.0));
116
            Qi.push_back(cv::Point3f(checkerSize * w, checkerSize* h, 0.0));
117
 
117
 
118
    std::vector< std::vector<cv::Point3f> > Q0, Q1, QStereo;
118
    std::vector< std::vector<cv::Point3f> > Q0, Q1, QStereo;
119
    for(int i=0; i<qc0.size(); i++)
119
    for(unsigned int i=0; i<qc0.size(); i++)
120
        Q0.push_back(Qi);
120
        Q0.push_back(Qi);
121
    for(int i=0; i<qc1.size(); i++)
121
    for(unsigned int i=0; i<qc1.size(); i++)
122
        Q1.push_back(Qi);
122
        Q1.push_back(Qi);
123
    for(int i=0; i<nValidSets; i++)
123
    for(unsigned int i=0; i<nValidSets; i++)
124
        QStereo.push_back(Qi);
124
        QStereo.push_back(Qi);
125
 
125
 
126
    // calibrate the cameras
126
    // calibrate the cameras
127
    SMCalibrationParameters cal;
127
    SMCalibrationParameters cal;
128
    cal.frameWidth = calibrationData[0].frame0.cols;
128
    cal.frameWidth = calibrationData[0].frame0.cols;
Line 164... Line 164...
164
        if(success0[i]){
164
        if(success0[i]){
165
            int n = (int)Q0[idx].size();
165
            int n = (int)Q0[idx].size();
166
            std::vector<cv::Point2f> qc_proj;
166
            std::vector<cv::Point2f> qc_proj;
167
            cv::projectPoints(cv::Mat(Q0[idx]), cam_rvecs0[idx], cam_tvecs0[idx], cal.K0,  cal.k0, qc_proj);
167
            cv::projectPoints(cv::Mat(Q0[idx]), cam_rvecs0[idx], cam_tvecs0[idx], cal.K0,  cal.k0, qc_proj);
168
            float err = 0;
168
            float err = 0;
169
            for(int j=0; j<qc_proj.size(); j++){
169
            for(unsigned int j=0; j<qc_proj.size(); j++){
170
                cv::Point2f d = qc0[idx][j] - qc_proj[j];
170
                cv::Point2f d = qc0[idx][j] - qc_proj[j];
171
                err += cv::sqrt(d.x*d.x + d.y*d.y);
171
                err += cv::sqrt(d.x*d.x + d.y*d.y);
172
            }
172
            }
173
            cal.cam0_errors_per_view[i] = (float)err/n;
173
            cal.cam0_errors_per_view[i] = (float)err/n;
174
            idx++;
174
            idx++;
Line 181... Line 181...
181
        if(success1[i]){
181
        if(success1[i]){
182
            int n = (int)Q1[idx].size();
182
            int n = (int)Q1[idx].size();
183
            std::vector<cv::Point2f> qc_proj;
183
            std::vector<cv::Point2f> qc_proj;
184
            cv::projectPoints(cv::Mat(Q1[idx]), cam_rvecs1[idx], cam_tvecs1[idx], cal.K1,  cal.k1, qc_proj);
184
            cv::projectPoints(cv::Mat(Q1[idx]), cam_rvecs1[idx], cam_tvecs1[idx], cal.K1,  cal.k1, qc_proj);
185
            float err = 0;
185
            float err = 0;
186
            for(int j=0; j<qc_proj.size(); j++){
186
            for(unsigned int j=0; j<qc_proj.size(); j++){
187
                cv::Point2f d = qc1[idx][j] - qc_proj[j];
187
                cv::Point2f d = qc1[idx][j] - qc_proj[j];
188
                err += cv::sqrt(d.x*d.x + d.y*d.y);
188
                err += cv::sqrt(d.x*d.x + d.y*d.y);
189
            }
189
            }
190
            cal.cam1_errors_per_view[i] = (float)err/n;
190
            cal.cam1_errors_per_view[i] = (float)err/n;
191
            idx++;
191
            idx++;
Line 272... Line 272...
272
    cv::Matx34f P1 = cv::Matx34f(RT1);
272
    cv::Matx34f P1 = cv::Matx34f(RT1);
273
 
273
 
274
    // calibration points in camera 0 frame
274
    // calibration points in camera 0 frame
275
    std::vector< std::vector<cv::Point3f> > Qcam;
275
    std::vector< std::vector<cv::Point3f> > Qcam;
276
 
276
 
277
    for(int i=0; i<nValidSets; i++){
277
    for(unsigned int i=0; i<nValidSets; i++){
278
        std::vector<cv::Point2f> qc0i, qc1i;
278
        std::vector<cv::Point2f> qc0i, qc1i;
279
 
279
 
280
        cv::undistortPoints(qc0[i], qc0i, cal.K0, cal.k0);
280
        cv::undistortPoints(qc0[i], qc0i, cal.K0, cal.k0);
281
        cv::undistortPoints(qc1[i], qc1i, cal.K1, cal.k1);
281
        cv::undistortPoints(qc1[i], qc1i, cal.K1, cal.k1);
282
//        qc0i = qc0[i];
282
//        qc0i = qc0[i];