Note that there are some explanatory texts on larger screens.

plurals
  1. POerror during camera calibration in OpenCV
    text
    copied!<p>I am doing camera calibration using opencv. I am using the same code given in "Cook book programming". </p> <p>I am taking pictures from my smartphone of a chessboard. Then I am using opencv program to do camera calibration for me. Program worked for only one set of images when I have very large chess board. It does not work for other set of images and I get run time error "Assertion failed <img src="https://i.stack.imgur.com/Tpe23.png" alt="enter image description here"></p> <p>I dont know what going wrong in my code. The code is as follows:-</p> <pre><code>int main() { CameraCalibrator calibrateCam; std::vector&lt;std::string&gt; filelist; char buff[100]; for(int i=0;i&lt;21;i++) { sprintf(buff,"..\\Train\\3\\%d.jpg",i+1); filelist.push_back(buff); } cv::Size boardSize(4,3); double calibrateError; int success; success = calibrateCam.addChessboardPoints(filelist,boardSize); } class CameraCalibrator{ public: std::vector&lt;std::vector&lt;cv::Point3f&gt;&gt; objectPoints; std::vector&lt;std::vector&lt;cv::Point2f&gt;&gt; imagePoints; //Square Lenght float squareLenght; //output Matrices cv::Mat cameraMatrix; //intrinsic cv::Mat distCoeffs; //flag to specify how calibration is done int flag; //used in image undistortion cv::Mat map1,map2; bool mustInitUndistort; public: CameraCalibrator(): flag(0), squareLenght(36.0), mustInitUndistort(true){}; int addChessboardPoints(const std::vector&lt;std::string&gt;&amp; filelist,cv::Size&amp; boardSize){ std::vector&lt;std::string&gt;::const_iterator itImg; std::vector&lt;cv::Point2f&gt; imageCorners; std::vector&lt;cv::Point3f&gt; objectCorners; //initialize the chessboard corners in the chessboard reference frame //3d scene points for(int i = 0; i&lt;boardSize.height; i++){ for(int j=0;j&lt;boardSize.width;j++){ objectCorners.push_back(cv::Point3f(float(i)*squareLenght,float(j)*squareLenght,0.0f)); } } //2D Image points: cv::Mat image; //to contain chessboard image int successes = 0; for(itImg=filelist.begin(); itImg!=filelist.end(); itImg++){ image = cv::imread(*itImg,CV_LOAD_IMAGE_GRAYSCALE); std::cout&lt;&lt;*itImg&lt;&lt;"\n"; bool found = cv::findChessboardCorners(image, boardSize, imageCorners); cv::drawChessboardCorners(image, boardSize, imageCorners, found); cv::cornerSubPix(image, imageCorners, cv::Size(5,5),cv::Size(-1,-1), cv::TermCriteria(cv::TermCriteria::MAX_ITER+cv::TermCriteria::EPS,30,0.1)); //if we have a good board, add it to our data if(imageCorners.size() == boardSize.area()){ addPoints(imageCorners,objectCorners); successes++; } } return successes; } void addPoints(const std::vector&lt;cv::Point2f&gt;&amp; imageCorners,const std::vector&lt;cv::Point3f&gt;&amp; objectCorners){ //2D image point from one view imagePoints.push_back(imageCorners); //corresponding 3D scene points objectPoints.push_back(objectCorners); } double calibrate(cv::Size &amp;imageSize){ mustInitUndistort = true; std::vector&lt;cv::Mat&gt; rvecs,tvecs; return cv::calibrateCamera(objectPoints, //the 3D points imagePoints, imageSize, cameraMatrix, //output camera matrix distCoeffs, rvecs,tvecs, flag); } void remap(const cv::Mat &amp;image, cv::Mat &amp;undistorted){ std::cout &lt;&lt; cameraMatrix; if(mustInitUndistort){ //called once per calibration cv::initUndistortRectifyMap( cameraMatrix, distCoeffs, cv::Mat(), cameraMatrix, image.size(), CV_32FC1, map1,map2); mustInitUndistort = false; } //apply mapping functions cv::remap(image,undistorted,map1,map2,cv::INTER_LINEAR); } }; </code></pre> <p>In camera calibration class, it opens the image successfully but it fails on findChessboardCorners line . . . </p> <p>Plz help me in that. One sample chess board image is as follows. The algorithm fails on this very 1st image to find the corners . . . . :-<img src="https://i.stack.imgur.com/Q0Zzl.jpg" alt="enter image description here"> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload