Detecting LED object status from image

My question is similar to OpenCV: detecting flashing lights in a video stream openCV detects flashing lights

I want to determine the on / off status of the LED from any image that the LED object will have. The LED object can have any size (but basically a circle). It is important that the location of all the LEDs is in this image, although it can be turned on or off. First of all, I would like to get the status and position of the LEDs, which are included only. Right now, the image source is static for my work, but it should be from a video of any product that has glowing LEDs. Thus, there is no way to create a template image to align the background.

I tried using OpenCV (new to OpenCV) with threshold, loop, and circular methods, but did not find it successful. Please share if there is any source code or solution. The solution can be any that not only uses OpenCV, which will give the result for me. It would be very helpful.

The difference from the other two questions is that I want to get the number of LEDs in the image, regardless of whether it can be ON, OFF or the status of all the LEDs. I know this is very difficult. First of all, I tried to detect the glowing LEDs in the image. I implemented the code that I described below. I had different implementations, but below the code is able to show me glowing LEDs, just by drawing outlines, but the number of outlines is greater than the glowing LEDs. Therefore, I can not get the total number of LEDs glowing at least. Please offer me your details.

int main(int argc, char* argv[]) { IplImage* newImg = NULL; IplImage* grayImg = NULL; IplImage* contourImg = NULL; float minAreaOfInterest = 180.0; float maxAreaOfInterest = 220.0; //parameters for the contour detection CvMemStorage * storage = cvCreateMemStorage(0); CvSeq * contours = 0; int mode = CV_RETR_EXTERNAL; mode = CV_RETR_CCOMP; //detect both outside and inside contour cvNamedWindow("src", 1); cvNamedWindow("Threshhold",1); //load original image newImg = cvLoadImage(argv[1], 1); IplImage* imgHSV = cvCreateImage(cvGetSize(newImg), 8, 3); cvCvtColor(newImg, imgHSV, CV_BGR2HSV); cvNamedWindow("HSV",1); cvShowImage( "HSV", imgHSV ); IplImage* imgThreshed = cvCreateImage(cvGetSize(newImg), 8, 1); cvInRangeS(newImg, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed); cvShowImage( "src", newImg ); cvShowImage( "Threshhold", imgThreshed ); //make a copy of the original image to draw the detected contour contourImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 3); contourImg=cvCloneImage( newImg ); cvNamedWindow("Contour",1); //find the contour cvFindContours(imgThreshed, storage, &contours, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); int i = 0; for (; contours != 0; contours = contours->h_next) { i++; //ext_color = CV_RGB( rand()&255, rand()&255, rand()&255 ); //randomly coloring different contours cvDrawContours(contourImg, contours, CV_RGB(0, 255, 0), CV_RGB(255, 0, 0), 2, 2, 8, cvPoint(0,0)); } printf("Total Contours:%d\n", i); cvShowImage( "Contour", contourImg ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "Threshhold" ); cvDestroyWindow( "HSV" ); cvDestroyWindow( "Contour" ); cvReleaseImage( &newImg ); cvReleaseImage( &imgThreshed ); cvReleaseImage( &imgHSV ); cvReleaseImage( &contourImg ); } 
+4
source share
1 answer

I have last 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 single channel image
  • Look for the brightest pixel, assuming that we have at least one LED and a dark background, as in your image.
  • Create a binary image with the brightest part of the image
  • Remove the droplets from the image, remove their center and the number of LEDs.

At this point, the code only takes into account the image, but you can improve it with a loop to take a packet of images (I already have some sample images in my repo). You just need to play a little with the center found for the LEDs, as they may not be accurate from one image to another (the center may shift slightly).

To get the algorithm more reliable (find out if there is an LED or not, find the automatic rather than hard-coded field value), you can play a little with the histogram (placed in extract_bright). I already created a function for this, you just need to improve it a bit.

Additional input information: Opencv only accepts avi files , so you will need to convert the mp4 file to avi (uncompressed in my case). I used this one that worked great. For some reason, the queryframe function caused a memory leak on my computer. That's why I created grab_images functions that take an avi file as input and create a batch of jpg images that you can use more easily.

Here is the result for the 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 a little more complicated if you want to use this image . The method I posted can still be used, but it should be a bit complicated.

You want to detect LEDs that display โ€œinformationโ€ (status, bandwidth, ...) and discard the design part.

I see three simple solutions:

  • You have previous knowledge of the position of the LEDs. In this case, you can apply the same method, but on the exact part of the entire image (using cv.SetImageROI).
  • you have a known knowledge of the color of the LEDs (you can see in the image that there are two different colors). You can then search the entire image and then apply a color filter to limit your selection.
  • you do not have previous knowledge. In this case, things get a little more complicated. I would like to say that LEDs that are not useful should have the same color, and these LEDs usually blink. This means that by adding a learning step to the method, you can see which LEDs should really be selected as useful.

Hope this brings more food for thought.

+5
source

Source: https://habr.com/ru/post/1413741/


All Articles