简体   繁体   English

图像中的目标检测

[英]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. 为此,我得到图像和指定的元素(如鼻子),然后从Pixel(0,0)开始搜索我的元素。 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 . 我将从viola jones对象检测框架开始

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) AFAIK,它在OpenCV库中实现(我不熟悉该库以提供帮助)

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 一个很好的实现是例如OpenCV的matchTemplate函数

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. 同样,OpenCV具有一个不错的Blob库,用于处理此类问题。

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. 假设此组件始终以相同的尺寸绘制,则顶线和底线始终相距21个像素。 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. 通过将此图像与其垂直方向偏移21个像素的副本进行组合,并将两个图像中较亮的一个作为每个位置的像素值,可以大大缩小搜索空间。

(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. 同样,此组件左右两边的垂直线相距47像素,因此我们可以使用47像素的水平移位重复此过程。 This results in a vertical bar about 24px tall at the position of the component. 这将在组件位置处产生大约24px高的垂直条。

(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. 通过在经过处理的图像的垂直列中查找22至26像素长的黑色像素,可以很容易地检测到这些条。 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. 这将为您提供候选位置的简短列表,您可以在其中更彻底地检查此组件的存在,例如,通过计算局部2D互相关。

Here are the results after processing the whole image. 这是处理整个图像后的结果。 Reaching this stage should only take a few milliseconds. 到达此阶段仅需几毫秒。

(Image removed by request) (图片已根据要求删除)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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