Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Exception while drawing oriented MBB with minAreaRect

As stated in the title, i'm trying to draw the oriented minimum bounding box of a blob through the use of findContours() and minAreaRect(). The problem is the following exception is thrown at runtime:

OpenCV Error: Assertion failed (points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S)) in cv::minAreaRect, file C:\buildslave64\win64_amdocl\2_4_PackSlave-win32-vc11-shared\opencv\modules\imgproc\src\contours.cpp, line 1913

My code is as follows:

// Drawing oriented MBB
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    findContours(blobs , contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0,0));
    RotatedRect minRect = minAreaRect(blobs);
    Point2f vertices[4]; 
    minRect.points(vertices);
    for (int v = 0; v < 4; v++)
        line(blobs[b], vertices[v], vertices[(v+1)%4], Scalar(130));

The exception is thrown by the minAreaRect() function. The image on which i'm working is well initialized, since I saved it to file just before the code above, getting this result:

image description

Anyone has an idea of what the problem could be?

Ps: I'm using openCV 2.4.11 on Visual Studio 2012, Windows 10 machine