5

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.

Jean-Luc
  • 3,563
  • 8
  • 40
  • 78
  • You could look into the paper mentioned in [this question](http://stackoverflow.com/q/1364976/1601291). It might be overkill, and certainly not trivial. – Aurelius Jul 05 '13 at 05:17
  • Is it possible to post a copy of the original image without the green boxes? Or are you trying to do the detection *including* them? – Aurelius Jul 05 '13 at 06:49

2 Answers2

2

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?

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Thanks for that, I think this might be slightly beyond my capabilities. I've only been using OpenCV for about a week and I've never really studied this kind of thing (I'm an electrical engineering student). Nonetheless, I understand what would need to be done, just implementing it is the challange! – Jean-Luc Jul 05 '13 at 13:51
0

You can utilize color information and kmeans clustering as explained in the link.

As long as target object color differs from the background, the pixels of the square object can be detected accurately.

fatihk
  • 7,789
  • 1
  • 26
  • 48