Java and OpenCV color detection

微笑、不失礼 提交于 2019-12-11 22:11:30

问题


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


回答1:


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...



来源:https://stackoverflow.com/questions/37854040/java-and-opencv-color-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!