-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalibC.cpp
More file actions
86 lines (61 loc) · 2.04 KB
/
calibC.cpp
File metadata and controls
86 lines (61 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <opencv2/opencv.hpp>
#include <iostream>
#include <cstdlib>
#include <cstdlib>
#include <random>
#include <vector>
#include "opencv2/features2d/features2d.hpp"
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace std;
using namespace cv;
class CameraCalibrator{
//points in world coordinates
std::vector<std::vector<cv::Point3f>> objectPoints;
//points on image
std::vector<std::vector<cv::Poin2f>> imagePoints;
cv::Mat cameraMatrix;
cv::Mat distCoeffs;
int flag;
//Open chessboard images and extract corner points
int CameraCalibrator::addChessboardPoints(const std::vector<std::string> & filelist, cv::Size & boardSize){
//points on chessboard
std::vector<cv::Point2f> imageCorners;
std::vector<cv::Point3f> objectCorners;
//3D scene points of chessboard
for(int i=0; i<boardSize.height; i++){
for(int j=0; j<boardSize.width; j++){
objectCorners.push_back(cv::Point3f(i, j, 0.0f));
}
}
//2D image point of chessboard
cv::Mat image;
int successes = 0
for(int i=0; i<filelist.size(); i++){
image = cv::imread(filelist[i], 0);
bool found = cv::findChessboardCorners(image, boardSize, imageCorners);
//get subpixel accuracy on the corners
if(found){
cv::cornerSubPix(image, imageCorners, cv::Size(5,5), cv::Size(-1,-1), cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0.1));
if(imageCorners.size() == boardSize.area()){
//Add image and scene points from one view
addPoints(imageCorners, objectCorners);
successes++;
}
}
if(imageCorners.size() == boardSize.area()){
addPoints(imageCorners, objectCorners);
successes++;
}
}
return successes;
}
//Calibrate camera and return re-projection error
double CameraCalibrator::calibrate(cv::Size &imageSize){
//output rotations and translation
std::vector<cv::Mat> rvecs, tvecs;
return calibrateCamera(objectPoints, imagePoints, imageSize, cameraSize, cameraMatrix, distCoeffs, rvecs, tvecs, flag);
}
}
int main(int argv, char** argc){
}