Detecting LED object status from Image

前端 未结 1 611
日久生厌
日久生厌 2021-02-01 11:28

My question is similar to OpenCV: Detect blinking lights in a video feed openCV detect blinking lights

I want to detect LED on/off status from any image which will have

相关标签:
1条回答
  • 2021-02-01 12:13

    I has some time yesterday night, here is a (very) simple and partial solution that works fine for me. I created a git repository that you can directly clone :

    git://github.com/jlengrand/image_processing.git

    and run using Python

    $ cd image_processing/LedDetector/
    $ python leddetector/led_highlighter.py
    

    You can see the code here

    My method :

    • Convert to one channel image
    • Search for brightest pixel, assuming that we have at least one LED on and a dark background as on your image
    • Create a binary image with the brightest part of the image
    • Extract the blobs from the image, retrieve their center and the number of leds.

    The code only takes an image into account at this point, but you can enhance it with a loop to take a batch of images (I already provides some example images in my repo.) You simply have to play around a bit with the center found for LEDs, as they might not be one pixel accurate from one image to another (center could be slightly shifted).

    In order to get the algorithm more robust (know whether there is a LED on or not, find an automatic and not hard coded margin value), you can play around a bit with the histogram (placed in extract_bright). I already created the function for that you should just have to enhance it a bit.

    Some more information concerning the input data : Opencv does only accept avi files for now, so you will have to convert the mp4 file to avi (uncompressed in my case). I used this, that worked perfectly. For some reason, the queryframe function caused memory leaks on my computer. That is why I created the grab_images functions, that takes the avi file as input and creates a batch of jpg images that you can use easier.

    Here is the result for an image :

    Input image :

    Input example

    Binary image :

    Binary result (brightest part of the image)

    Final result :

    Final result (Bounding boxes surrounding the LEDs)

    Hope this helps. . .

    EDIT :

    Your problem is slightly more complex if you want to use this image. The method I posted could still be used, but needs to be a bit complexified.

    You want to detect the leds that display 'an information' (status, bandwidth, . . . ) and discard the design part.

    I see three simple solutions to this :

    • you have a previous knowledge of the position of the leds. In this case, you can apply the very same method, but on a precise part of the whole image (using cv.SetImageROI).
    • you have a previsous knowledge of the color of the leds (you can see on the image that there are two different colors). Then you can search the whole image, and then apply a color filter to restrain your choice.
    • you have no previous knowledge. In this case, things get a bit more complex. I would tend to say that leds that are not useful should all have the same color, and that status leds usually blink. This means that by adding a learning step to the method, you might be able to see which leds actually have to be selected as useful.

    Hope this brings some more food for thoughts

    0 讨论(0)
提交回复
热议问题