错误向量迭代器不兼容 - opencv

时间:2012-10-26 22:00:36

标签: c++ exception opencv vector iterator

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

我将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 .....
}    

以下是我遇到的例外情况。 exception encountered

0 个答案:

没有答案