Ask Your Question
0

minAreaRect of vector of vector of points

asked 2014-07-09 04:26:49 -0500

João M. S. Silva gravatar image

From the documentation, minAreaRect takes an InputArray and an InputArray can be a std::vector<std::vector<T>>.

However I'm getting an assertion error when calling minAreaRect with vector<vector<Point>>:

  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/matrix.cpp:977: error: (-215) 0 <= i && i < (int)vv.size() in function getMat

Isn't Point a "T"?

edit retag flag offensive close merge delete

Comments

vector<vector<Point>> is a vector of contours, you should apply minAreaRect to a single contour, a vector<Point>, like contours[3]

berak gravatar imageberak ( 2014-07-09 04:31:10 -0500 )edit

But the documentation explicitly says InputArray can either be a vector&lt;T&gt; or a vector&lt;vector&lt;T&gt;&gt;, among others.

João M. S. Silva gravatar imageJoão M. S. Silva ( 2014-07-09 04:33:44 -0500 )edit
berak gravatar imageberak ( 2014-07-09 04:34:47 -0500 )edit

ok, yea, an InputArray can be anything. but not all of it makes sense in the given context.

berak gravatar imageberak ( 2014-07-09 04:36:26 -0500 )edit

I guess it would make sense. You can take the minAreaRect of a contour as well as of a set of contours, why not? If not, why allow vector&lt;vector&lt;T&gt;&gt;?

João M. S. Silva gravatar imageJoão M. S. Silva ( 2014-07-09 04:38:38 -0500 )edit

if you try, you will get a runtime exception. so, it's not allowed.

can we settle it here ?

berak gravatar imageberak ( 2014-07-09 04:43:03 -0500 )edit

We can: you ran out of arguments so you used a fallacy. That's common.

João M. S. Silva gravatar imageJoão M. S. Silva ( 2014-07-09 04:48:54 -0500 )edit

I would say T is a template type, so if I use T=vector< vector< vector< vector< cv::Point > > > > is still an InputArray. Therefore, it means you have to understand: InputArray could be a vector< vector< T, but it's a convenient way of writing things. There is no function able to work on all type, that the point with template, and therefore, when you are using a template, usually (always?) the class needs some basic requirement. In that case, it's that the function is working "only" with a list of points, not many list of points. Nevertheless, I will add 2 things: First, if you have a valuable impovement to make to the doc, please make a pull request. Second, if you are able to implement minAreaRect with vector of vector, please also make a pull request, therefore everyone can use it.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2014-07-09 06:01:20 -0500 )edit

And to add to this discussion, afaik there is a difference between templates of form vector of vectors and a vector only. Let me clear this out

 - In the docs a vector of T is used IF the function has a InputArray as parameter.
 - However functions like drawContours have a parameter called InputArrayOfArrays. In that case a vector of vectors of type T have to be used.

I understand the original author of this topic wants to argue that T, which is a template can be of any type and thus also of vector, however not a single OpenCV function is capable of dealing with such understanding.

Also adding the function for a vector of vector of points is quite useless and not extra functionality, you should just run over the indices of the master vector and iteratively run the operation.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-09 06:35:22 -0500 )edit

I asked because I really didn't know. I was not trying to argue about T, which in fact I was not sure what it could mean (I interpreted it could be "anything" but not a vector).

What caused my doubt is the explicit mention to vectors of vectors: http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=inputarray#InputArray

Anyway I tried to create a vector or RotatedRect's in the first pass and then get the minAreaRect of that vector but I get a different assertion error: what(): /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/contours.cpp:1913: error: (-215) points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S) in function minAreaRect

Is it possible to compute the RotatedRect of the set of contours using API functions? Thanks.

João M. S. Silva gravatar imageJoão M. S. Silva ( 2014-07-09 09:40:11 -0500 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2014-07-11 08:14:54 -0500

João M. S. Silva gravatar image

I worked around it using C++ vector functions:

vector<Point> selected;
for (unsigned int i = 0; i < N; i++) {
  vector<Point> contour = ...
  selected.insert(selected.end(), contour.begin(), contour.end());
}
rotated_rect = minAreaRect(selected);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-07-09 04:26:49 -0500

Seen: 2,385 times

Last updated: Jul 11 '14