Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you only got 1 vector of objectPoints,

 vector<vector<Point3f>> object_points(1);

but it needs to be the same size as your imagepoints ( 10 in the end), one object_point vector per corner vector.

also, i think, your calculation of the object_points is wrong, that'll never make an artificial chessboard.

so, try this instead:

const float squareSize = 1.f;  // Set this to your actual square size
vector<vector<Point3f> > objectPoints(numImages);

for( int i = 0; i < numPairs; i++ )
{
    for( int j = 0; j < numCornersVer; j++ )
        for( int k = 0; k < numCornersHor; k++ )
            objectPoints[i].push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));
}

you only got 1 vector of objectPoints,

 vector<vector<Point3f>> object_points(1);

but it needs to be the same size as your imagepoints ( 10 in the end), one object_point vector per corner vector.

also, i think, your calculation of the object_points is wrong, that'll never make an artificial chessboard.

so, try this instead:

const float squareSize = 1.f;  // Set this to your actual square size
vector<vector<Point3f> > objectPoints(numImages);

for( int i = 0; i < numPairs; i++ )
{
    for( int j = 0; j < numCornersVer; numCornersHor; j++ )
        for( int k = 0; k < numCornersHor; numCornersVer; k++ )
            objectPoints[i].push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));
}

you only got 1 vector of objectPoints,

 vector<vector<Point3f>> object_points(1);

but it needs to be the same size as your imagepoints ( 10 in the end), one object_point vector per corner vector.

also, i think, your calculation of the object_points is wrong, that'll never make an artificial chessboard.

so, try this instead:

const float squareSize = 1.f;  // Set this to your actual square size
vector<vector<Point3f> > objectPoints(numImages);
objectPoints(numBoards);

for( int i = 0; i < numPairs; numBoards; i++ )
{
    for( int j = 0; j < numCornersHor; j++ )
        for( int k = 0; k < numCornersVer; k++ )
            objectPoints[i].push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));
}

you only got 1 vector of objectPoints,

 vector<vector<Point3f>> object_points(1);

but it needs to be the same size as your imagepoints ( 10 in the end), one object_point vector per corner vector.

also, i think, your calculation of the object_points is wrong, that'll never make an artificial chessboard.

so, try this instead:

/* physical position of the corners (in 3D space) */
vector<vector<Point3f> > object_points;
/* location of corners in the image (in 2D space) */
vector<vector<Point2f>> image_points;
/* corners in the current chessboard image */
vector<Point2f> corners;
/* ??? */
int successes = 0;

Mat image;
Mat gray_image;

const float squareSize = 1.f;  // Set this to your actual square size
vector<vector<Point3f> > objectPoints(numBoards);

vector<Point3f> model;
for( int j = 0; j < numCornersHor; j++ )
    for( int k = 0; k < numCornersVer; k++ )
        model.push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));

for( int i = 0; i < numBoards; i++ )
{
    for( int j = 0; j < numCornersHor; j++ )
        for( int k = 0; k < numCornersVer; k++ )
            objectPoints[i].push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));
image = imread(imageList[successes], CV_LOAD_IMAGE_COLOR);
    /* convert image into a grayscale image */
    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);
        image_points.push_back(corners);
        object_points.push_back(model);
        successes++;
    } 
}

you only got 1 vector of objectPoints,

 vector<vector<Point3f>> object_points(1);

but it needs to be the same size as your imagepoints ( 10 in the end), one object_point vector per corner vector.

also, i think, your calculation of the object_points is wrong, that'll never make an artificial chessboard.

so, try this instead:

/* physical position of the corners (in 3D space) */
vector<vector<Point3f> > object_points;
/* location of corners in the image (in 2D space) */
vector<vector<Point2f>> image_points;
/* corners in the current chessboard image */
vector<Point2f> corners;
/* ??? */
int successes = 0;

Mat image;
Mat gray_image;

const float squareSize = 1.f;  // Set this to your actual square size

vector<Point3f> model;
for( int j = 0; j < numCornersHor; j++ )
    for( int k = 0; k < numCornersVer; k++ )
        model.push_back(Point3f(float(j)*squareSize, float(k)*squareSize, 0));

for( int i = 0; i < numBoards; i++ )
{
    image = imread(imageList[successes], imread(imageList[i], CV_LOAD_IMAGE_COLOR);
    /* convert image into a grayscale image */
    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);
        image_points.push_back(corners);
        object_points.push_back(model);
        successes++;
    } 
}