Ask Your Question

# How to detect square in a video using c++ and opencv?

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.i want to detect square shape objects which are situated near the road. As a example . the program simply check whether the frame that taken by camera (which is putting inside the vehicle) has square sign or not.(if that frame has square shape object then frame is sent to next function, else delete that)

edit retag close merge delete

## Comments

Could you please attach examples of images? Should detection be robust to different scaling, rotations, affine and perspective distortions?

( 2012-08-10 14:04:01 -0500 )edit
1

thank you very much for helping. i attached an example to this question.

( 2012-08-10 14:58:32 -0500 )edit
1

Thank you, it helps to understand the problem better. Both Chamfer Matching and Line2D should work correctly with such images. Chamfer Matching is a classic algorithm for edge-based detection and Line2D is a state-of-the-art algorithm published at ICCV 2011. I would recommend to use Line2D because it is more robust but you can try both algorithms for this task.

( 2012-08-10 15:31:40 -0500 )edit

Thank you very much.now on words i'm going to study about both Chamfer Matching and Line2D. i think i could find solution from them.

( 2012-08-10 15:40:30 -0500 )edit

## 1 answer

Sort by ยป oldest newest most voted

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.

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2012-08-10 13:43:13 -0500

Seen: 5,110 times

Last updated: Aug 10 '12