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.
Asked
Active
Viewed 5,530 times
0
-
possible duplicate of [How to find object on video using OpenCV](http://stackoverflow.com/questions/10788271/how-to-find-object-on-video-using-opencv) – karlphillip Jun 05 '12 at 17:02
-
1@karlphillip: one more +1 for you for 'horrible' comment. – Abid Rahman K Jun 05 '12 at 17:04
2 Answers
4
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

Martin Beckett
- 94,801
- 28
- 188
- 263
-
Sir thank you very much for your reply. i used hough transform for image processing? but is that working for video processing? – Thar1988 Jun 06 '12 at 15:14
-
1@Tk1988 - video is just images. If speed matters you might use another technique to quickly check if the square is in the same place as the last frame and if not do Hough again. Or you can limit the Hough search space to parameters near to the last hit – Martin Beckett Jun 06 '12 at 15:20
0
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!!!

Abid Rahman K
- 51,886
- 31
- 146
- 157
-
There is a large number of examples on Stackoverflow that shows how to achieve these 2 tasks separately, I talk about them [here](http://stackoverflow.com/questions/10788271/how-to-find-object-on-video-using-opencv), when I replied his other question. I believe this question right here is a duplicate. – karlphillip Jun 05 '12 at 17:23
-
1Yeah.. just checked that link. Link to square detection clearly given in your answer. There was no need to ask this question, unless he wanted something else. – Abid Rahman K Jun 05 '12 at 17:30