简体   繁体   English

OpenCV C ++从二进制映像中提取功能

[英]OpenCV C++ extract features from binary image

I have written an algorithm to process a camera capture and extract a binary image of two features I'm interested in. I'm trying to find the best (fastest) way of detecting when the two features intersect and where the lowest (y coordinate is greatest) point is (this will be the intersection). 我编写了一种算法来处理相机捕获并提取我感兴趣的两个特征的二进制图像。我试图找到检测这两个特征何时相交以及最低(y坐标)在哪里的最佳(最快)方法最大)点是(这将是交集)。

I do not want to use a findContours() based method as this is too slow and, in my opinion, unnecessary. 我不想使用基于findContours()的方法,因为这太慢了,我认为这是不必要的。 I also think blob detection libraries are too bloated for this. 我还认为,blob检测库对此过于too肿。

I have two sample images (sorry for low quality): 我有两个示例图像(对不起,质量低下):

(not touching: http://i.imgur.com/7bQ9qMo.jpg ) (touching: http://i.imgur.com/tuSmKw7.jpg ) (不触摸: http : //i.imgur.com/7bQ9qMo.jpg )(触摸: http : //i.imgur.com/tuSmKw7.jpg

Due to the way these images are created, there is often noise in the top right corner which looks like pixelated lines but methods such as dilation and erosion lose resolution around the features I'm trying to find. 由于这些图像的创建方式,通常在右上角会出现噪点,看起来像是像素化的线条,但是诸如扩张和腐蚀之类的方法在我要寻找的要素周围失去了分辨率。

My initial thought would be to use direct pixel access to form a width filter and a height filter. 我最初的想法是使用直接像素访问来形成宽度滤镜和高度滤镜。 The lowest point in the image is therefore the intersection. 因此,图像中的最低点是交点。

I have no idea how to detect when they touch... logically I can see that a triangle is formed when they intersect and otherwise there is no enclosed black area. 我不知道如何检测它们何时接触...从逻辑上我可以看到,当它们相交时会形成一个三角形,否则就没有封闭的黑色区域。 Can I fill the image starting from the corner with say, red, and then calculate how much of the image is still black? 我可以从角落开始用红色填充图像,然后计算多少图像仍然是黑色?

Does anyone have any suggestions? 有没有人有什么建议?

Thanks 谢谢

Your suggestion is a way more slow than finding contours. 您的建议比找到轮廓要慢得多。 For binary images, finding contour is very easy and quick because you just need to find a black pixel followed by a white pixel or vice versa. 对于二值图像,找到轮廓非常容易且快速,因为您只需要先找到一个黑色像素,再找到一个白色像素,反之亦然。

Anyway, if you don't want to use it, you can use the vertical projection or vertical profile you will see it the objects intersect or not. 无论如何,如果您不想使用它,则可以使用垂直投影或垂直轮廓,您将看到对象是否相交。

For example, in the following image check the the letter "n" which is little similar to non-intersecting object, and the letter "o" which is similar to intersecting objects : 例如,在下面的图像中,检查与非相交对象几乎相似的字母“ n”和与相交对象相似的字母“ o”: 在此处输入图片说明

By analyzing the histograms you can recognize which one is intersecting or not. 通过分析直方图,您可以识别哪个相交或不相交。

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

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