English 中文(简体)
从图像中检测 LED 对象状态
原标题:Detecting LED object status from Image

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

我想从任何带有 LED 对象的图像中检测出 LED 状态。 LED 对象可以是任何大小的(但大多是圆 ) 。 重要的是要在该图像中找到所有 LED 的位置, 尽管它可以是 On 或 OutF 。 首先,我想获得只使用 LED 的状态和位置。 现在, LED 的图像源是静态的, 对我的工作来说, 但它必须来自任何带有 LED 光发产品的视频。 因此没有机会用模板图像来减小背景 。

我尝试了使用 OpenCV (新到 OpenCV) 的门槛、 轮廓和圆形方法, 但没有找到可生成的 。 如果有源代码或解决方案, 请分享 。 解决方案不仅可以使用 OpenCV 来给我带来结果, 请分享 。

与另外两个问题的不同之处在于,我想在图像中找到LED的数量,不管是在屏幕上,还是在FTF上,以及所有LED的状态。我知道这非常复杂。首先,我试图在图像中检测发光的LED。我实施了下面分享的代码。我实施了不同的执行程序,但低于代码,我只能通过绘制轮廓来显示发光的LED,但轮廓的数量比发光的LED还多。所以我无法找到发光的LED的总数。请建议我你的投入。

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
", i);
cvShowImage( "Contour", contourImg );

cvWaitKey(0);
cvDestroyWindow( "src" ); cvDestroyWindow( "Threshhold" );
cvDestroyWindow( "HSV" );
cvDestroyWindow( "Contour" );
cvReleaseImage( &newImg ); cvReleaseImage( &imgThreshed ); 
cvReleaseImage( &imgHSV );
cvReleaseImage( &contourImg );



}
最佳回答

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_ process.git /jlengrand/image_ process.git /git / git / git / git/github. com/jlengrand/image_ process.git/

使用 Python 运行

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

您可以看到代码""https://github.com/jlengrand/image_ process/tree/master/Led Disator" rel=“noreferrer'>这里

我的方法:

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

以下是图像的结果:

输入图像 :

"https://i.sstatic.net/B3m3n.jpg" alt="Input example"/> https://i.sstatic.net/B3m3n.jpg" alt="Input example"/ > 。

二进制图像 :

恶性结果(图像最亮的部分)

最终结果:

最后结果(环绕LED的盒子)

希望这能帮上忙

<强 > EDIT:

如果您想要使用 < a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

您想要检测显示信息( 状态、 带宽、..) 和丢弃设计部分的线索 。

我看到三个简单的解决办法:

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

希望这能带来更多思考的食粮

问题回答

暂无回答




相关问题
Resources for Image Recognition

I am looking for a recommendation for an introduction to image processing algorithms (face and shape recognition, etc.) and wondered if anyone had an good recommendations, either for books, ...

Good reference book for digital image processing? [closed]

I am learning digital image processing on my own and would like recomendations on good reference books. If you know of books to definately stay away from that would be useful as well. Thanks

Python Tesseract can t recognize this font

I have this image: I want to read it to a string using python, which I didn t think would be that hard. I came upon tesseract, and then a wrapper for python scripts using tesseract. So I started ...

What s the quickest way to parallelize code?

I have an image processing routine that I believe could be made very parallel very quickly. Each pixel needs to have roughly 2k operations done on it in a way that doesn t depend on the operations ...

Computing object statistics from the second central moments

I m currently working on writing a version of the MATLAB RegionProps function for GNU Octave. I have most of it implemented, but I m still struggling with the implementation of a few parts. I had ...

Viola-Jones face detection claims 180k features

I ve been implementing an adaptation of Viola-Jones face detection algorithm. The technique relies upon placing a subframe of 24x24 pixels within an image, and subsequently placing rectangular ...

热门标签