Ask Your Question
0

Issue with detecting combinations of squares

asked 2017-05-08 05:47:37 -0600

gryzly123 gravatar image

Hello,

I am making a program that allows the user to put white square-shaped items (pieces of paper or blocks, whatever he has) on the table and get the pattern made of these blocks detected by the camera (for example one item, two items connected together and so on, including domino-like mazes). What I have at the moment:

  • Getting data from camera and conversion to cv::Mat
  • Conversion from RGB to HSV and thresholding
  • Contour detection through findContours() (using CV_RETR_CCOMP and CV_CHAIN_APPROX_SIMPLE)
  • Conversion from contours to rotated bounding boxes through minAreaRect()

My next idea is to get a list of points (coordinates on camera image) where the blocks are (to determine whether the block is in that particular point, and to possibly detect its color if the requirements change) based on the bounding box and the area it covers. Here's the idea and my issue:

Issue

I know that this is not a bug - the feature works correctly because this is indeed a smaller rectangle that the shape fits in.

My question is: are there any alternatives to minAreaRect() that would take shape edges into consideration?

Thanks in advance :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-05-08 17:34:17 -0600

Tetragramm gravatar image

So, I shall assume you can isolate just the blocks and their contours. Before you do minAreaRect, you should analyze the contours. Since you have just the edges of the boxes, you can estimate the rotation needed to make them vertical and horizontal lines.

Then rotate the image to make the edges vertical and horizontal. Your bounding box is then a tight, non rotated box around the contours, which should be simple.

edit flag offensive delete link more

Comments

Rotating the entire image seems like an overkill so I rotated the contours instead. The solution works for the complex shapes but sometimes tends to fail on the simple cases (though that just might be because my implementation is faulty somewhere). But yes, this seems like the most correct approach to the situation so I'm marking it as resolved :)

gryzly123 gravatar imagegryzly123 ( 2017-05-11 03:53:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-08 05:47:37 -0600

Seen: 480 times

Last updated: May 08 '17