1 | initial version |
If shape is the most distinguishable feature then you should use edges to detect such an object. A simple and fast approach is to use Chamfer Matching which is available in the OpenCV contrib module. You should specifiy square as a template and then this algorithm will find a square in Canny edges of a test image. See a sample chamfer.cpp how to use this function.
2 | No.2 Revision |
If shape is the most distinguishable feature then you should use edges to detect such an object. A simple and fast approach is to use Chamfer Matching which is available in the OpenCV contrib module. You should specifiy square as a template and then this algorithm will find a square in Canny edges of a test image. See a sample chamfer.cpp how to use this function.
Another solution is to use the Line2D algorithm from the OpenCV objdetect module (see a sample linemod.cpp). This algorithm is more robust in cluttered scenes.