Ask Your Question

Exception while drawing oriented MBB with minAreaRect

asked 2016-02-08 12:38:26 -0600

Drakem gravatar image

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]; 
    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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-08 12:45:53 -0600

berak gravatar image

updated 2016-02-08 12:48:54 -0600

cv::minAreaRect works on a (single) contour, not on an image, did you want : minAreaRect(contours[some_index]) ?

edit flag offensive delete link more


Well, i'm very ashamed to say my mistake was as stupid as that... Sorry, i was doing a lot of editing on the code and i lost the line of developing.

Drakem gravatar imageDrakem ( 2016-02-08 12:52:14 -0600 )edit

don't be ashamed, ... it just happens ;)

berak gravatar imageberak ( 2016-02-08 12:59:01 -0600 )edit

Question Tools

1 follower


Asked: 2016-02-08 12:38:26 -0600

Seen: 468 times

Last updated: Feb 08 '16