I want to build an program that can detect square shape object in a video. i used SURF algorithm for that. but that only detect key points.
-
possible duplicate of How to find object on video using OpenCVkarlphillip– karlphillip2012-06-05 17:02:36 +00:00Commented Jun 5, 2012 at 17:02
-
1@karlphillip: one more +1 for you for 'horrible' comment.Abid Rahman K– Abid Rahman K2012-06-05 17:04:34 +00:00Commented Jun 5, 2012 at 17:04
2 Answers
The normal way would be to detect edges with a canny filter then a hough transform to find lines and then find pairs of lines with slopes that are 90deg different
2 Comments
The code for square detection ( specifically rectangle, you can modify a little bit to work it for squares only) comes directly with opencv samples and you get it when you download the OpenCV library.
You didn't specify the language you work. But the code comes in Python and C++.
How it works:
- Split image in to R,G,B plane
- For each plane, threshold image for a range values in 0 to 255
- Find the contours, approximate, and select the ones with only 4 points
- Find cosine of angle between all the lines of the contour and check if close to 90
- If so, it is rectangle
- If you want square, check if its all sides are almost equal.
It works pretty well. And if you have seen this, and this is not what you want, update your question with more specific details, including some test images.
Hope it helps!!!