How can I find minimum area rectangle in binary image?

Discussion related to "under the hood" OpenMV topics.
pencilpen
Posts: 2
Joined: Fri Dec 07, 2018 10:45 pm

How can I find minimum area rectangle in binary image?

Postby pencilpen » Fri Dec 07, 2018 11:02 pm

I have EmguCV project to find all minimum area rectangle in contour like below.

VB.NET with EmguCV code :
imgRects.Draw(CvInvoke.MinAreaRect(contour), New Bgr(Color.Red), 3)

How can I find minimum area rectangle in binary image like vb.net code as above?
Attachments
1544242126100.jpg
1544242110947.jpg
User avatar
kwagyeman
Posts: 2467
Joined: Sun May 24, 2015 2:10 pm

Re: How can I find minimum area rectangle in binary image?

Postby kwagyeman » Sat Dec 08, 2018 12:18 am

Hi, please clarify how this relates to the OpenMV Cam?

We don't have a min area rect method. However, if you care about rotation the find_blobs() method returns the rotation angle of the object. Otherwise what is your goal with the min area rect?
Nyamekye,
pencilpen
Posts: 2
Joined: Fri Dec 07, 2018 10:45 pm

Re: How can I find minimum area rectangle in binary image?

Postby pencilpen » Sat Dec 08, 2018 12:50 am

Thank you for you fast reply. In my previous project, I use visual studio with emgu cv to measures width and length of object. In last project, I use openmv with non-distortion lens. Then I want to make embeded machine to use mesure width and length of object and have light display when found defect.

So I want to measure minimum area rectangle. That in my previous project, I use function as below.

CvInvoke.CvtColor(imgROI, imgHSV, ColorConversion.Bgr2Hsv)
CvInvoke.InRange

CvInvoke.FindContours(...............................

imgRects.Draw(CvInvoke.MinAreaRect(contour), New Bgr(Color.Red), 3)


Please suggess me.
User avatar
kwagyeman
Posts: 2467
Joined: Sun May 24, 2015 2:10 pm

Re: How can I find minimum area rectangle in binary image?

Postby kwagyeman » Sat Dec 08, 2018 11:23 pm

I understand what you need to do. Um, so the rect we return has a left/right/up/down parts. However, this ins't the min area rect... but, the min area rect intersects these points.

Anyway, the easiest way to get this is to take the rotation angle from the find_blobs() function and rotate the rectangle corners by a 2D rotation matrix.


E.g.

For each point of the of the rect do trate the point as:

[X
Y]

and the mulitply by: https://en.wikipedia.org/wiki/Rotation_matrix where pheta is the rotation angle from find_blobs().

...

I understand you'd prefer some working code versus how to do it but I am answering this from not at home right now and I'm unable to write some code for this. However, we can add this feature to the firmware. Please submit a github ticket issue for it.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests