我正在开发一个 OpenCV 项目,并且正在进行校准。我相信我已经正确地实现了代码;但是我得到了不同的相机矩阵值,有时变化很大。在 6 次重复显示校准模式 10 次后,我得到(为清楚起见截断小数):
[573, 0, 386;
0, 573, 312;
0, 0, 1]
[642, 0, 404;
0, 644, 288;
0, 0, 1]
[664, 0, 395;
0, 665, 272;
0, 0, 1]
[629, 0, 403;
0, 630, 288;
0, 0, 1]
[484, 0, 377;
0, 486, 307;
0, 0, 1]
[644, 0, 393;
0, 643, 289;
0, 0, 1]
这些值相差不可接受的量。我需要相当准确地知道给定参数是什么。这些大的不准确的典型原因是什么,我如何评估给定矩阵的正确性?这似乎取决于我展示图案的距离和方向的多样性,但我无法理解图案。
代码:
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(1);
if(!cap.isOpened())
return -1;
cap.set(CV_CAP_PROP_FRAME_WIDTH,800);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,600);
Mat edges;
Size size(9,17);
int counter = 10;
vector<Point2f> corners;
bool found;
vector<Point3f> chess = fr::ChessGen::getBoard(size,1,true);
vector<vector<Point3f> > objectPoints;
vector<vector<Point2f> > imagePoints;
Mat camera = Mat::eye(3,3,CV_64F);
Mat distortion = Mat::zeros(8, 1, CV_64F);
vector<Mat > rvecs;
vector<Mat > tvecs;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame;
cvtColor(frame, edges, CV_BGR2GRAY);
found = findCirclesGrid(edges,size,corners
,CALIB_CB_ASYMMETRIC_GRID
);
if(found) frame.convertTo(edges,-1,0.2);
drawChessboardCorners(edges,size,corners,found);
imshow("edges", edges);
if(found){
if(waitKey(200)>=0){
objectPoints.push_back(chess);
imagePoints.push_back(corners);
if(--counter<= 0)
break;
}
}
else waitKey(30);
}
calibrateCamera(objectPoints,imagePoints,Size(800,600),camera,distortion,rvecs,tvecs,0);
if(found) imwrite("/home/ryan/snapshot.png",edges);
cout << camera << endl;
return 0;
}