简体   繁体   中英

OpenCV Error: Camera Calibration: Assertion failed in matrix_wrap.cpp

The Error:

OpenCV(3.4.1) Error: Assertion failed (i < 0) in cv::debug_build_guard::_InputArray::getMat_, 
file C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\matrix_wrap.cpp, line 50

The Code inside "matrix_wrap.cpp" that triggers the Error:

if( k == STD_VECTOR )
{
    CV_Assert( i < 0 );
    int t = CV_MAT_TYPE(flags);
    const std::vector<uchar>& v = *(const std::vector<uchar>*)obj;

    return !v.empty() ? Mat(size(), t, (void*)&v[0]) : Mat();
}

Entire Code:

#include <iostream>    
#include <opencv2/opencv.hpp>  


int main(int argc, char *argv[])
{
cv::Mat img = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);

cv::Size imageSize = cv::Size(img.size[0], img.size[1]);

cv::Mat cameraMatrix, distCoeffs;

double squareSize = 30;

cv::Size boardSize = cv::Size(6, 11);

std::vector<cv::Point2f> imagePoints;
std::vector<cv::Point3f> objectPoints;

for (int i = 0; i < boardSize.height; i++) {
    for (int j = 0; j < boardSize.width; j++) {
        objectPoints.push_back(
            cv::Point3f(float(j * squareSize), float(i * squareSize), 0));
    }
}

std::vector<cv::Mat>  rvecs, tvecs;

bool found = false;

if (img.size[0] > 1)
{

    bool found = findChessboardCorners(img, boardSize, imagePoints, cv::CALIB_CB_ADAPTIVE_THRESH);

    if (found)
    {
        drawChessboardCorners(img, boardSize, imagePoints, found);
    }

    objectPoints.resize(imagePoints.size(), objectPoints[0]);

    double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);

    cv::namedWindow("My Image");
    cv::imshow("My Image", img);
    cv::waitKey(1000);

}
return 0;
}

I want to use a basic camera calibration with a straigth chessboard. Until the function "calibrateCamera" everything works fine, but I can't figure out why this Error shows up.

The size of "objectPoints" and "imagePoints" is the same. Thank you in advance.

PS: I'm new in this forum and also in OpenCV ;)

As per this source of opencv , lines 3139 and 3142 :

CV_Error(CV_StsUnsupportedFormat, "objectPoints should contain vector of vectors of points of type Point3f");
CV_Error(CV_StsUnsupportedFormat, "imagePoints1 should contain vector of vectors of points of type Point2f");

the types for objectPoints and imagePoints should be std::vector<std::vector<Point{2|3}f>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM