1

我正在尝试使用 opencv 校准我的相机。我找到了本教程,但我遇到了“错误向量迭代器不兼容”异常。

我将 image_points 声明如下:

vector<vector<Point2f>> image_points;

角落如下:

vector<Point2f> corners;

在以下 3 个 OpenCV 调用中使用了角点:

    bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

    if(found)
    {
        cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
        drawChessboardCorners(gray_image, board_sz, corners, found);
    }

并在尝试像这样推动 image_points 上的角时出现异常:

if ( key == ' ' && found != 0 )
    image_points.push_back(corners);

谁能暗示什么是错的?

编辑:发布完整代码

#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace cv;
using namespace std;

int main()
{
    int numBoards = 3;
    int numCornersHor = 9;
    int numCornersVer = 6;

    int numSquares = numCornersHor * numCornersVer;
    Size board_sz = Size(numCornersHor, numCornersVer);

    VideoCapture capture = VideoCapture(0);

    vector<vector<Point3f>> object_points;
    vector<vector<Point2f>> image_points;

    vector<Point2f> corners;
    int successes=0;

    Mat image;
    Mat gray_image;
    capture >> image;

    vector<Point3f> obj;
    for(int j=0;j<numSquares;j++)
        obj.push_back( Point3f( (j * 1.0f) / numCornersHor, ( j % numCornersHor ) * 1.0f, 0.0f ) );

    while(successes < numBoards)
    {
        cvtColor(image, gray_image, CV_BGR2GRAY);

        bool found = findChessboardCorners(image, board_sz, corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

        if(found)
        {
            cornerSubPix(gray_image, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
            drawChessboardCorners(gray_image, board_sz, corners, found);
        }

        imshow("win2", gray_image);

        capture >> image;

        int key = waitKey(1);
        if(key==27)
            return 0;

        if(key==' ' && found!=0)
        {
            // the next line throws the exception.
            image_points.push_back(corners);
            object_points.push_back(obj);
            printf("Snap stored!\n");

            successes++;

            if(successes>=numBoards)
                break;
        }
    }
    // the program never reaches this point

    // do more stuff .....
}    

以下是我遇到的异常。 遇到异常

4

0 回答 0