Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 'Almost' Closed contours

Tags:

c++

opencv

I'm trying to extract the cube from the image (looks like a square...). I've used canny and dilate to get the edges and remove the noise.

I'm not even sure if it is possible to get the square out in a robust way.

Advice appreciated!

image

Thanks.

like image 815
Jean-Luc Avatar asked Nov 03 '22 19:11

Jean-Luc


1 Answers

It's not excessively hard.

Sort all edges by direction. Look for a pair of edges in one direction with another pair 90 degrees rotated. Check for rough proximity. If so, they probably form a rectangle. Check the edge distances to pick the squares from the rectangles, and to discard small squares. Check if you have sufficiently large parts of the edge to be convinced the entire edge must exist. An edge might even be broken in 2. Check if the 4 edges now found delimit an area that is sufficiently uniform.

The last bit is a bit tricky. That's domain knowlegde. Could there be other objects inside the square, and could they touch or overlap the edges of the square?

like image 56
MSalters Avatar answered Nov 08 '22 10:11

MSalters