3

I am trying to detect a vehicle in an image (actually a sequence of frames in a video). I am new to opencv and python and work under windows 7.

Is there a way to get horizontal edges and vertical edges of an image and then sum up the resultant images into respective vectors?

Is there a python code or function available for this.

I looked at this and this but would not get a clue how to do it. You may use the following image for illustration.

EDIT

I was inspired by the idea presented in the following paper (sorry if you do not have access).

Betke, M.; Haritaoglu, E. & Davis, L. S. Real-time multiple vehicle detection and tracking from a moving vehicle Machine Vision and Applications, Springer-Verlag, 2000, 12, 69-83

https://i.sstatic.net/y5MXl.jpg

3 Answers 3

1

I would take a look at the squares example for opencv, posted here. It uses canny and then does a contour find to return the sides of each square. You should be able to modify this code to get the horizontal and vertical lines you are looking for. Here is a link to the documentation for the python call of canny. It is rather helpful for all around edge detection. In about an hour I can get home and give you a working example of what you are wanting.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. The image (square) I supplied is for illustration purposes only since I do not have a free image of vehicle on the road
If you happen to know exactly what the rear of the vehicle looks like, and can assume it remains a relative constant, then I would recommend using template matching. In the case that it is constant, then it might be a bit more accurate, and less computationally stressful.
The idea of template would may narrow down the region of interest. Unfortunately real-life problems are not basic algorithm friendly. The video I have is on the road and I need to identify each of the vehicle the driver encompasses.
Understandably so. I actually happened to write a program a year or so ago in c that detected the license plates from a dash cam. Although it is not what I finalized with, template matching actually worked relatively well in that situation. One thing to note, with many cars the lines that would be detected on them are not always horizontal and vertical. You might want to expand your system to include certain patterns of lines. Like that of a rounded trapezoid(windshield).
Apologies for the delay, I turned out to be busier than expected. I think I found that paper, so I will post a sample once I have read it.
1

Do some reading on Sobel filters.

http://en.wikipedia.org/wiki/Sobel_operator

You can basically get vertical and horizontal gradients at each pixel.

Here is the OpenCV function for it.

http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#sobel

Once you get this filtered images then you can collect statistics column/row wise and decide if its an edge and get that location.

Comments

1

Typically geometrical approaches to object detection are not hugely successful as the appearance model you assume can quite easily be violated by occlusion, noise or orientation changes.

Machine learning approaches typically work much better in my opinion and would probably provide a more robust solution to your problem. Since you appear to be working with OpenCV you could take a look at Casacade Classifiers for which OpenCV provides a Haar wavelet and a local binary pattern feature based classifiers.

The link I have provided is to a tutorial with very complete steps explaining how to create a classifier with several prewritten utilities. Basically you will create a directory with 'positive' images of cars and a directory with 'negative' images of typical backgrounds. A utiltiy opencv_createsamples can be used to create training images warped to simulate different orientations and average intensities from a small set of images. You then use the utility opencv_traincascade setting a few command line parameters to select different training options outputting a trained classifier for you.

Detection can be performed using either the C++ or the Python interface with this trained classifier. For instance, using Python you can load the classifier and perform detection on an image getting back a selection of bounding rectangles using:

image = cv2.imread('path/to/image')
cc = cv2.CascadeClassifier('path/to/classifierfile')
objs = cc.detectMultiScale(image)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.