I am working on a program that takes realtime captured image.
The goal is to track an object in the foreground. and highlight the object as it moves around the background.
This is done using subtarction, find connected components, set ROI for saving time processing canny and hough transform,
and then draw the lines into the captured image
Now the problem occurs when openCV tries to draw lines in the captured image, even though I checked the background has correct width and height,
the program will crash regardless as soon as I move the background (in this case, a table)
The error says "One of the arguments' value is out of range (Image width or height are negative) in function cvClipLine
Usually the background is saved as a IplImage and as long as the back ground is undisturbed opencv won't crash most of the time
but I want to understand why opencv has this error when my image is perfectly fine.
cvCanny( ImageGray, ImageEdge, 50, 200, 3 );
cvThreshold( ImageEdge, ImageEdge, 30, 255, CV_THRESH_BINARY );
CvMemStorage* storage = cvCreateMemStorage( 0 );
CvPoint pt[100][2];
CvSeq* lines = cvHoughLines2( ImageEdge, storage, CV_HOUGH_STANDARD, 1, CV_PI/180, 30, 0, 0 );
for( int i = 0; i < MIN( lines->total, 60 ); i++ ) {
float* line = (float*)cvGetSeqElem( lines, i );
float rho = line[0];
float theta = line[1];
double a = cos( theta ), b = sin( theta );
double x0 = a * rho, y0 = b * rho;
pt[i][0].x = cvRound( x0 + 1000 * ( -b ) );
pt[i][0].y = cvRound( y0 + 1000 * ( a ) );
pt[i][1].x = cvRound( x0 - 1000 * ( -b ) );
pt[i][1].y = cvRound( y0 - 1000 * ( a ) );
//// ERROR HAPPEND HERE
cvLine( Image, pt[i][0], pt[i][1], CV_RGB( 255, 0, 0 ), 3, CV_AA, 0 );
}
A screen shot of the image shows that the captured image has width and height above zero, and yet the program complains about the crash
[img]
http://i40.tinypic.com/x6oo3.jpg[/img]
Here's the source code of cvLine at 01737
[url]
http://opencv.sourcearchive.com/documentation/1.0.0-6.1/cxdrawing_8cpp-source.html[/url]
at some point in cvLine, it does some calculations to image Width and Height, and then it called cvClipLine, I checked the calculation myself and I don't see why the program can crash at cvClipline because the values passed in are all positive even after the processing.