图像处理中的形状检测
我正在致力于检测任何物体的形状。我有一个二值图像,其中背景为白色,前景/对象为黑色。我需要检测前景中黑色物体的形状。
我该怎么做?形状可能是人/车/盒子等。请帮忙
I'm working on detecting the shape of any object. I have a binary image where the background is in white and the foreground/object is in black. I need to detect the shape of the object in the foreground which is in black.
How can i do it? The shape may be of a man/car/box etc. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定哪个是你的最终目标,正如 amphetamachine 所说,但检测形状的一种非常常见的方法可能是使用 cvFindContours ,它给出一个二进制图像并返回一组 'CvContour< /strong>'(实际上是一个 cvSeq)。通过对图像进行阈值处理(cvThreshold),可以非常简单地检索二值图像。查看opencv src目录的sample/中的contours.c示例。另请检查此链接:
Noah (2009) opencv 教程
此示例代码会给你一个大概的想法:
一旦你有了轮廓的编码,你就可以使用cvMatchShapes,它采用2个轮廓并返回这些轮廓之间的相似性度量。
希望这种方法能为您提供一个良好的开端!
I'm not sure which is your final goal as amphetamachine said but a pretty common approach to detect shapes could be the use of cvFindContours which given a binary image and returns a set of 'CvContour' (which in fact is a cvSeq). Binary image can be retrieved quite simple by thresholding the image (cvThreshold). Check out the contours.c example in the sample/ of opencv src directory. Check this link as well:
Noah (2009) opencv tutorial
this sample code will give you an general idea:
Once you have an encoding of the contour you can use cvMatchShapes which take 2 contours and return a measure of similarity between these contours.
Hope this approach provide you a head start!
为了准确的形状检测,您需要使用 haar 检测或至少 K 最近邻。 Haar检测可以非常准确,但设置时间较长。 K 最近邻更容易设置,但不太准确。观看此 YouTube 视频。这家伙正在使用 KNN 来检测不同的手势。请注意,比较图像基本上是一个黑色斑点。 KNN 的缺点是它需要花费更多的资源来运行程序,但是使用 haar 检测,当您使用 haartraining.exe 创建级联 xml 文件时,主要处理已经完成
For accurate shape detection you need to use haar detection or at the least K nearest neighbor. Haar detection can be very accurate, but it takes a long time to set up. K nearest neighbor is easier to set up but is not as accurate. Check out this youtube video. This guy is using KNN to detect different hand gestures. Notice that the comparison image is basically a black blob. The bad thing about KNN is that it is that it takes a lot more resources to run the program, but with haar detection, the major processing has already been done when you create the cascade xml files with haartraining.exe