Java和OpenCV颜色检测 [英] Java and OpenCV color detection

查看:915
本文介绍了Java和OpenCV颜色检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学校开展一个项目,主要是:编写一个应用程序让无人机自动飞行,并通过扫描挂在墙上的QR码,能够在房间内导航以完成一个某些任务。



我目前正在研究的是无人机检测纸箱(作为障碍物)。这些盒子是白色的,上面有一个蓝色圆圈。我打算如何解决这个问题,就是扫描框架中的颜色和方块:



如果无人机检测到一个正方形,检查它是否为白色。如果是白色,请检查它是否包含蓝色圆圈。如果是这样,我可以说它很可能是一个纸板箱。



这就是方框:





如果有人能提供一些关于我如何开始进行颜色检测的指示,我会很开心的!



PS:我没有提供任何代码,因为我真的不知道提供什么。如果需要,我会非常乐意提供一些



更新:对于遇到与我相同问题的人,同学为我的确切情况提供了一个很好的链接:





另一种(更强大的)可能性是同时选择所有与白色和蓝色相邻的黑色像素。


  • 进行连通分量分析



    所以将所有连接的像素合并为折线


  • 对于每条折线决定是否是圆/椭圆/椭圆



    可以通过调查线段之间的角度来完成。如果有尖锐的尖峰,则存在锋利的边缘并且它不是椭圆形。如果圆周距圆形/椭圆/椭圆太远而无法从其边界框计算出来,那么它不是椭圆形,而是一些更复杂的曲率。


  • For每个椭圆形决定它是否填充蓝色



    所以只需填充卵形圆周的填充掩模,并比较原始图像蓝色与那些像素的数量不是。如果比率接近100%蓝色则填充蓝色椭圆形....



    因为你的标记内部还有一些功能可以计算所有比例其中的基色可以更准确地检测标记。



    查看算法:其他一些想法的椭圆匹配


  • 现在您可以同样检查背景是否为白色/灰色


  • 还有很多其他可能的方法,例如 OCR和字符相似性或基于FFT / DCT,圆形的Hough变换......您也不仅限于几何属性比较,你可以比较直方图......


    I'm working on a project at school, which basically is: writing an application to make a drone fly autonomously, and through scanning QR-codes hung up on walls, be able to navigate through a room in order to complete a certain task.

    What I am currently working on, is for the drone to detect cardboard boxes (working as obstacles). These boxes are white, and have a blue circle on them. How I'm planning to solve this, is by scanning the frame for colors and squares:

    If the drone detects a square, check if it's white. If it's white, check if it contains a blue circle. If it does, I can say that it most likely is a cardboard box.

    This is what the box looks like:

    If anyone would be able to provide some pointers as to how I can start working on the color detection, I would be very happy!

    PS: I haven't provided any code, since I don't really know what to provide. I would be more than happy to provide some if needed

    UPDATE: for anyone stuck at the same problem as I, a fellow student provided an excellent link for my exact situation:

    http://opencv-java-tutorials.readthedocs.io/en/latest/08-object-detection.html

    解决方案

    I would go from a different angle to do this by detecting the blue circle first.

    1. Detect base colors

      see RGB value base color name

    2. Select all blue pixels neighboring white or gray-ish ones

      As your circlehas black border then you have to select all blue pixels near white,gray,black... just to be sure. This is the result (Green are selected pixels):

      another (more robust) possibility is to select all black pixels neighboring white and blue at the same time.

    3. do a connected components analysis

      so merge all connected pixels into polylines

    4. For each polyline decide if it is circle/ellipse/oval

      that can be done by investigating angle between line segments. If has sharp spikes then sharp edges are present and it is not an oval. If the circumference is too far from circle/elipse/oval computed from its bounding box then it is not oval but some more complicated curvature.

    5. For each oval decide if it is filled with blue

      so just flood fill mask of the oval circumference and compare how many pixels are int the original image blue against those that are not. if the ratio is closer to 100% blue then it is filled blue oval shape....

      As your marker has also some features inside you can compute the ratio of all base colors inside it to more accurately detect the marker.

      Look at Algorithms: Ellipse matching for some additional ideas.

    6. now you can similarly check if the background is white/gray-ish

    There are a lot of other possible approaches like OCR and character similarity or based on FFT/DCT, Hough transform for circles... also you are not bound only to geometric properties comparation instead you can compare histograms...

    这篇关于Java和OpenCV颜色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆