snippet.cpp
1 | int StereoVision::calibrationError() {
|
---|---|
2 | cv::Size imageSize; |
3 | int Nimg, Npts;
|
4 | vector<vector<cv::Point3f> > objectPoints; |
5 | vector<vector<cv::Point2f> >imagePoints; |
6 | cv::FileStorage f("calib_debug.yml",cv::FileStorage::READ);
|
7 | cv::FileNodeIterator it = f["img_sz"].begin(); it >> imageSize.width >> imageSize.height;
|
8 | Nimg = (int) f ["NofImages"]; |
9 | Npts = (int) f["NofPoints"]; |
10 | for (int i=0; i<Nimg;i++) { |
11 | std::stringstream imagename; imagename << "image" << i;
|
12 | cv::FileNode img = f[imagename.str()]; |
13 | vector <cv::Point3f> ov; |
14 | vector <cv::Point2f> iv; |
15 | for (int j=0; j<Npts; j++) { |
16 | std::stringstream nodename; nodename << "node" << j;
|
17 | cv::FileNode pnt = img[nodename.str()]; |
18 | cv::Point3f op; |
19 | cv::Point2f ip; |
20 | cv::FileNodeIterator ot = pnt["objPnt"].begin(); ot >> op.x >> op.y >> op.z;
|
21 | cv::FileNodeIterator it = pnt["imgPnt"].begin(); it >> ip.x >> ip.y;
|
22 | iv.push_back(ip); |
23 | ov.push_back(op); |
24 | } |
25 | imagePoints.push_back(iv); |
26 | objectPoints.push_back(ov); |
27 | } |
28 | cv::Mat M,D; |
29 | vector<cv::Mat> R,T; |
30 | cv::calibrateCamera(objectPoints, imagePoints, imageSize, M, D,R,T, |
31 | CV_CALIB_FIX_ASPECT_RATIO + 1*CV_CALIB_FIX_K3 + 1*CV_CALIB_ZERO_TANGENT_DIST); |
32 | cv::FileStorage fo("calib_output.yml",cv::FileStorage::WRITE);
|
33 | fo << "M" << M;
|
34 | } |