简体   繁体   中英

Object Detection in an Image

I want to detect some elements in an Image. For this goal, i get the image and the specified element (like a nose) and from Pixel(0,0) start to search for my element. But the software performance is awful because i traverse the pixels one by one. I think i need some smart algorithm for this problem. And maybe the machine learning algorithm useful for this. What's your idea?

I would start with viola jones object detection framework .

This is a supervised learning technique, that allows you to detect any kind of object with high provavility.
(even though the article mainly refers to faces, but it is designed for general objects..).

If you chose this approach - your main chore is going to be to obtain a classified training set. You can later evaluate how good your algorithm is using cross-validation .

AFAIK, it is implemented in OpenCV library (I am not familiar with the library to offer help)

You can do a very fast cross correlation using the Fourier transformation of your image and search pattern

A good implementation is for example OpenCV's matchTemplate function

This will work best if your pattern always has the same rotation and scale accross your image. If it does not, you can repeat the search with several scaled/rotated versions of your pattern.

One advantage of this approach is that no training phase is required.


Another, simpler approach that would work in particular with your pattern is this:

Use connected component labeling to identify blobs with the right number of white pixels to be the center rectangle of your element. This will eliminate all but a few false positives. Concentrate your search on the remaining few spots. Again OpenCV has a nice Blob library for that sort of stuff.

If you're looking for simple geometric shapes in computer-generated images like the example you provided, then you don't need to bother with machine learning.

For example, here's one of the components you're trying to find in the original image:

(Image removed by request)

Assuming this component is always drawn at the same dimensions, the top and bottom lines are always going to be 21 pixels apart. You can narrow down your search space considerably by combining this image with a copy of itself shifted vertically by 21 pixels, and taking the lighter of the two images as the pixel value at each position.

(Image removed by request)

Similarly, the vertical lines at the left and right of this component are 47 pixels apart, so we can repeat this process with a 47px horizontal shift. This results in a vertical bar about 24px tall at the position of the component.

(Image removed by request)

You can detect these bars quite easily by looking for runs of black pixels between 22 and 26 pixels long in the vertical columns of the processed image. This will provide you with a short list of candidate positions where you can check for the presence of this component more thoroughly, eg by calculating a local 2D cross correlation.

Here are the results after processing the whole image. Reaching this stage should only take a few milliseconds.

(Image removed by request)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM