Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV how to Group Rectangles

I would like some help explaining how to use the opencv group rectangles function in python SHOWN HERE.

I am running 2 haar cascades to detect objects in the image, but now I would like to merge the rectangles together. I am guessing thats what the groupRectangles is used for.

cv2.groupRectangles(rectList, groupThreshold, eps, weights, levelWeights)

I am assuming that rectList is the vector returned by cv2.cascade.detectMultiScale()? Also I am not sure what the weights, and levelWeights are or what tehy are used for and would appreciate it if anyone could explain that, or show me where I can find out about it as i cant find it in the documentation.

Thanks for any help :-)

like image 472
Alex Avatar asked Oct 24 '22 02:10

Alex


1 Answers

Maybe something changed in the meantime, but following the link you provided the definition is:

cv2.groupRectangles(rectList, groupThreshold[, eps]) → rectList, weights

So yes, rectList is a list of rectangles, in your case you would use the one returned by cv2.cascade.detectMultiScale(). While the optional eps controls, how similar (in terms of position and size) two rectangles need to be to be merged, the groupThreshold indicates how many rectangles at least need to be merged into one in order the keep the merged one.

You will be returned the new list of rectangles and a weight for every rectangle, I assume the weight reflects how many rectangles where merged and how similar they were.

like image 158
Brandlingo Avatar answered Oct 27 '22 10:10

Brandlingo