Calibration error [1 Attachment]

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Calibration error [1 Attachment]

opencv-users mailing list
Hi,
 

 I am working on stereo vision for my study project.
 I face a problem when I try to store the image corners in imagePoint vector when I use push.back, the error in in the memory were it shows the memory is overloaded.  
 I am using vs2013 on windows 10 and openCV 3.0.
 

 This is my code:
 #include <opencv2/opencv.hpp>
 #include <iostream>
 

 using namespace cv;
 using namespace std;
 

 

 int main(){
 // Define the input virable from the user
 int numBoard = 0;
 int numCornHer;
 int numCornVer;
 int sucsses = 0; // How many sucess we have in finding the corner
 // ask the user of the input
 cout << "Enter the number of board you need for the calibration: " << endl;
 cin >> numBoard;
 cout << "Enter number of corner in Horezintal: ";
 cin >> numCornHer;
 cout << "Enter number of conrenr in vertical: ";
 cin >> numCornVer;
 

 //evaluate the input data for future work
 int numSquare = numCornHer*numCornVer;
 Size boardSize = Size(numCornHer, numCornVer);
 // Create a storage for point from the images for calibration
 

 vector<vector<Point3f>> objectPoints; // This is the phiscal point on the board
 vector<vector<Point2f>> imagePoint; // This to store the point in the image plane location of corner
 

 // This storage for finding corner
 vector<cv::Point2f> corners; // to hold the corner position
 int cornerCount = 0; // Indicate how many corners are find
 

 // This storage for the actual coordinate refrence we can use the dimension
 // as (0,0,0),(0,1,0),(0,2,0),.....(1,4,0),....
 vector<Point3f> obj;
 for (int j = 0; j < numSquare; j++){
 obj.push_back(Point3f((j / numCornHer) * 30, (j%numCornHer) * 30, 0.0f)); // we use a unit because we are ni=ot the concern to dimension
 //cout << Point3f((j / numCornHer)*30, (j%numCornHer)*30, 0.0f) << endl; // The dimisional is in mm
 }
 

 VideoCapture vid(0); // Define the camera and assing it's number
 

 if (!vid.isOpened()){
 cout << " The camera cannot be open..\n";
 }
 

 

 Mat frame;
 Mat grayImg; // to store the gray image for process
 namedWindow("Left Window");
 

 // This loop to store the corner in the opbjectpoint
 bool bSucssCornerFind = true;
 while (bSucssCornerFind){
 

 bool bSucsCapture = vid.read(frame);
 if (bSucsCapture == false){
 cout << "Error unable to capture frame ...\n";
 return -1;
 }
 

 cvtColor(frame, grayImg, CV_BGR2GRAY);
 //do a sharpen filter for the large resolution image
 if (grayImg.cols > 1500)
 {
 Mat temp;
 GaussianBlur(grayImg, temp, Size(0, 0), 105); //hardcoded filter size, to be tested on 50 mm lens
 addWeighted(grayImg, 1.8, temp, -0.8, 0, grayImg); //hardcoded weight, to be tested.
 //imwrite("test"+ imageList[k][i], viewGray) ;
 

 }
 
 //findChessboardCorners(grayImg,patternSize,corners,cornerCount,CV_CALIB_CB_FAST_CHECK);
 int patternWasFound = findChessboardCorners(grayImg, boardSize, corners, CV_CALIB_CB_ADAPTIVE_THRESH + CV_CALIB_CB_FILTER_QUADS);
 if (patternWasFound){
 cornerSubPix(grayImg, corners, Size(5, 5), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS, 30, 0.1));
 /*cout << "Corners found: " << corners.size() << endl;
 for (int i = 0; i < patternWasFound; i++){
 cout << corners << endl;
 }
 cout << "***************" << endl;*/
 }
 

 drawChessboardCorners(frame, boardSize, corners, patternWasFound);
 

 imshow("Left Window", frame);
 

 char iKey = waitKey('0');
 

 if (iKey == 'q'){
 break;
 return 0;
 }
 

 if (iKey == 's' && patternWasFound != 0 ){ // if the corner found and the user press s it will store the corner data in the imagePoint
 

 
 imagePoint.push_back(corners); // Store corners values in the image point for calibration
 
 objectPoints.push_back(obj); // Stroe the phisical position in the object point for calibration
 cout << "Corners Stored suceessfully.." << endl;
 sucsses++;
 iKey = '0';
 if (sucsses >= numBoard){
 bSucssCornerFind = false;
 }
 } //End if statment
 } //End the while loop
 

 // These storage for the intrinsic and distortion coffeicent
 Mat interinsic = Mat(3, 3, CV_32FC1);
 Mat distCoeffs;
 vector<Mat> Rvect;
 vector<Mat> Tvect;
 

 

 // Calibrate the camera
 calibrateCamera(objectPoints, imagePoint, frame.size(), interinsic, distCoeffs, Rvect, Tvect);
 

 // Test the result to show undistrotion image
 while (1){
 Mat undistortFrame;
 vid.read(frame);
 undistort(frame, undistortFrame, interinsic, distCoeffs);
 

 imshow("Left Window", frame);
 imshow("Left Undistorted window", undistortFrame);
 

 char iKey = waitKey('q');
 if (iKey == 'q'){
 break; // Exit the loop
 }
 }
 

 // Save the result in a xml file
 string filename = "C:\Picture" + string("CameraParameter.xml");
 FileStorage fs(filename, FileStorage::WRITE);
 fs << "cameraMatrix" << interinsic;
 fs << "distCoeffs" << distCoeffs;
 fs.release();
 cout << "Saved calibration matrices to " << filename << endl;
 cin.get(); // wait press enter to exit
 return 0;
 
 }
 

 Thank you,
 Abdulla
 

Loading...