Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Possible solutions for OpenCv Assertion Error problem

I am trying to write a simple module for Image Cropping - here's my code

cv::Mat img = input_frame;
cv::Mat finalImg;

// Set Region of Interest to the area defined by the box
int h = input_frame.rows;
int w = input_frame.cols;

cv::Rect roi(skeletonBound[0].x,skeletonBound[0].y,abs(skeletonBound[3].x - skeletonBound[0].x),abs(skeletonBound[3].y - skeletonBound[0].y));

if(!(roi.height <= h) && !(roi.width <= w))
{

    return -1;
}
else
{
    cv::Mat crop = input_frame(roi);
    cv::imshow("crop", crop);
    cv::imwrite("cropped.png", crop);
    cv::Mat finalImg(crop);

    finalImageToBeusedForDetection = finalImg; 
    cout << "Success : "; 
    return 1;
}

I am getting this error -

image description

I checked and rechecked the dimensions, they are correct. i am successfully able to run this code for about early 10-15 frames, later at certain point of time, the code crashes abruptly with above error log. There seems to be a very small problem which i am not able to figure out.

Previously, I was also getting the error where ROI was greater than the size of input image. In that scenario also, the above code worked fine for first 10-15 frames, and later it crashed. I couldn't figure out the problem and hence discarded the erroneous result frame.

I am using latest versions of OpenCv for C++ in Visual studio 2012.

Please help me out on this. I tried all web resources, and have spent pretty lot of time on the same.

click to hide/show revision 2
retagged

updated 2013-09-26 01:37:03 -0600

berak gravatar image

Possible solutions for OpenCv Assertion Error problem

I am trying to write a simple module for Image Cropping - here's my code

cv::Mat img = input_frame;
cv::Mat finalImg;

// Set Region of Interest to the area defined by the box
int h = input_frame.rows;
int w = input_frame.cols;

cv::Rect roi(skeletonBound[0].x,skeletonBound[0].y,abs(skeletonBound[3].x - skeletonBound[0].x),abs(skeletonBound[3].y - skeletonBound[0].y));

if(!(roi.height <= h) && !(roi.width <= w))
{

    return -1;
}
else
{
    cv::Mat crop = input_frame(roi);
    cv::imshow("crop", crop);
    cv::imwrite("cropped.png", crop);
    cv::Mat finalImg(crop);

    finalImageToBeusedForDetection = finalImg; 
    cout << "Success : "; 
    return 1;
}

I am getting this error -

image description

I checked and rechecked the dimensions, they are correct. i am successfully able to run this code for about early 10-15 frames, later at certain point of time, the code crashes abruptly with above error log. There seems to be a very small problem which i am not able to figure out.

Previously, I was also getting the error where ROI was greater than the size of input image. In that scenario also, the above code worked fine for first 10-15 frames, and later it crashed. I couldn't figure out the problem and hence discarded the erroneous result frame.

I am using latest versions of OpenCv for C++ in Visual studio 2012.

Please help me out on this. I tried all web resources, and have spent pretty lot of time on the same.