error help

Jul 15, 2013 at 5:41pm
Hey Programmers

I have decided to write my own camera calibration program instead of using findchessboard corners because of its inability to detect corners when occluded it really messes things up.

so i used goodfeaturestotrack combined with calibratecamera and i have finished the only problem is the actual calibratecamera function.

when i debug it and step and execute the line calibratecamera it results in an unhandled exception error.

below is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
int main()
{
	Mat image, grayscale;
	VideoCapture webcam;
	webcam.open(-1);
	int numcorners, horcorner,vercorner;
	Mat corners;
	printf("Enter number of corners horizontally: ");
    scanf("%d", &horcorner);
	printf("Enter number of corners vertically: ");
    scanf("%d", &vercorner);
	numcorners=horcorner*vercorner;
	namedWindow("original",1);
	
	vector<vector<Point3f>> object_points;
    vector<vector<Point2f>> image_points;

	vector<Point3f> obj;
	vector<Point2f> img;
    for(int j=0;j<numcorners;j++)
        obj.push_back(Point3f(float(j/vercorner), float(j%vercorner), 0.0f));		//setting up the units of calibration

	while(1)
	{
		//copy webcam stream to image
		webcam>>image;
		cvtColor(image,grayscale,CV_BGR2GRAY);
		//goodfeatures(grayimage, output to store corners, quality factor, distance factor)
		goodFeaturesToTrack(grayscale,corners,numcorners,0.1,20);
		// Mark these corners on the original image
		cornerSubPix(grayscale, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
		for(int i=0;i<corners.rows;i++)
		{
			//draws circle on image, at centre at point, color, thickness, line type, 
			circle(image,corners.at<Point2f>(i),3,CV_RGB(255,0,0),1,8,0);
		}

		// Print the number of corners
		cout<<corners<<endl;
		cout<<corners.at<Point2f>(0)<<endl;  //access the coordinates
		cout<<corners.at<float>(0,0)<<endl;  //access the first element of the first coordinates
		imshow("original",image);
		
		int key = waitKey(1);
		if(key==27)
            return 0;
		if(key==' ')
        {
			for(int k=0;k<corners.rows;k++)
			{
				img.push_back(corners.at<Point2f>(k));
			}
            image_points.push_back(img);
            object_points.push_back(obj);
            printf("Snap stored!\n");
			break;
		}
	}
	Mat intrinsic = Mat(3, 3, CV_32FC1);
    Mat distCoeffs;
    vector<Mat> rvecs;
    vector<Mat> tvecs;

	intrinsic.ptr<float>(0)[0] = 1;
    intrinsic.ptr<float>(1)[1] = 1;

	calibrateCamera(object_points, img, image.size(), intrinsic, distCoeffs, rvecs, tvecs);	//unhandled exception error at this point not because of too much points

	while(1)
	{
		webcam>>image;
		imshow("original",image);
		int key=waitKey(1);
		if(key==27)
			return 0;
	}
	return 0;
}


Error i get is:
OpenCV Error: Assertion failed (nimages > 0 && nimages == <int>imagePoints1.total() && (!imgPtMat2 || nimages == <int>imagePoints2.total())) in unknown function, file ..\..\..\src\opencv\modules\calib3d\src\calibration.cpp, line 3168


help would be appreciated
thanks
Last edited on Jul 15, 2013 at 6:49pm
Jul 15, 2013 at 7:20pm
If you write code yourself why do not you read errors? The assertion message text is clear enough.
Jul 16, 2013 at 4:59pm
I'm not good at interpreting error messages, but figured it out as i have one program that worked and checked to see what was different it should have been image_points and not img in the calibratecamera function second parameter.

it wasn't very clear to me
Jul 16, 2013 at 5:09pm
closed account (Dy7SLyTq)
your assert failed at line 3168 in calibration.cpp. how is that not clear?
Jul 16, 2013 at 9:39pm
because calibration.cpp is a pre built function file that is in the opencv file and when i go to that line. i don't what that line of code means its the same thing printed on the command window.
Topic archived. No new replies allowed.