从图像检测LED对象状态 [英] Detecting LED object status from Image

查看:78
本文介绍了从图像检测LED对象状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题类似于 OpenCV:检测视频中的闪烁灯提要 openCV检测闪烁的灯光

我想从任何具有LED对象的图像中检测LED的开/关状态. LED物体可以是任何大小(但多数是圆形).重要的是获取该图像中所有LED的位置,尽管它可以打开或关闭.首先,我想获取仅打开的LED的状态和位置.目前,在我的工作中,图像源是静态的,但它必须来自具有发光LED的任何产品的视频.因此,没有模板图像可以减去背景.

I want to detect LED on/off status from any image which will have LED object. LED object can be of any size ( but mostly circle ). It is important to get the location of all the LEDs in that image although it can be ON or OFF. First of all I would like to get the status and position of LEDs which are ON only. Right now image source is static for my work out but it must be from video of any product having glowing LEDs. So there is no chance of having template image to substract the background.

我尝试将OpenCV(OpenCV的新功能)与阈值,​​轮廓和圆弧方法一起使用,但未成功.如果有任何源代码或解决方案,请分享.解决方案不仅可以使用OpenCV,而且可以为我带来任何结果.这将不胜感激.

I have tried using OpenCV (new to OpenCV) with threshold, Contours and Circles methods but not found sucessful. Please share if any source code or solution. The solution can be anything not only using OpenCV which would give result for me. It would be greatly appreciated.

与其他两个问题的区别在于,我想获取图像中LED的数量(可以是ON还是OFF)以及所有LED的状态.我知道这很复杂.首先,我试图检测图像中发光的LED.我已经实现了下面共享的代码.我有不同的实现方式,但是下面的代码仅通过绘制轮廓就可以向我显示发光的LED,但是轮廓的数量要比发光的LED多.因此,我无法获得发光的LED总数.请向我建议您的意见.

The difference from other two question is that I want to get the number of LEDs in the image whether it can be ON or OFF and status of all LEDs. I know this is very complex. First of all I was trying to detect glowing LEDs in the image. I have implemented the code which i shared below. I had different implementations but below code is able to show me the glowing LEDs just by drawing the contours but number of contours are more than the glowing LEDs. So I am not able to get the total number of LEDs glowing atleast. Please suggest me your inputs.

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 );



}

推荐答案

昨天晚上我有一些时间,这是一个非常非常简单的解决方案,对我来说很好. 我创建了一个git存储库,您可以直接克隆它:

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

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

并使用Python运行

and run using Python

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

您可以在此处

我的方法:

  • 转换为一个频道图片
  • 假设您的图像上至少有一个LED亮着并且背景很暗,则搜索最亮的像素
  • 使用图像中最亮的部分创建二进制图像
  • 从图像中提取斑点,检索其中心和led的数量.

此刻代码仅考虑了图像,但是您可以通过循环来获取一批图像来增强它(我已经在存储库中提供了一些示例图像). 您只需要在找到LED的中心的位置上稍作调整,因为从一个图像到另一个图像的像素可能不准确(中心可能会稍微偏移).

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

为了使算法更健壮(了解是否有LED亮,找到一个自动的但不是硬编码的边距值),您可以使用直方图(放在 extract_bright 中). 我已经创建了该函数,您只需要对其进行一些增强即可.

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.

有关输入数据的更多信息: Opencv 目前仅接受avi文件,因此您必须将mp4文件转换为avi(在我的情况下未压缩).我使用了,工作完美. 由于某些原因, queryframe 函数导致计算机上的内存泄漏.这就是为什么我创建了 grab_images 函数的原因,该函数将avi文件作为输入并创建一批易于使用的jpg图像.

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.

这是图像的结果:

输入图片:

二进制图片:

最终结果:

希望这会有所帮助. . .

Hope this helps. . .

如果您要使用

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.

您要检测显示信息"(状态,带宽,...)的LED,并丢弃设计零件.

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

我看到了三个简单的解决方案:

I see three simple solutions to this :

  • 您已经了解了LED的位置.在这种情况下,您可以应用完全相同的方法,但是要应用到整个图像的精确部分(使用cv.SetImageROI).
  • 您对LED的颜色有很深的了解(可以在图像上看到两种不同的颜色).然后,您可以搜索整个图像,然后应用滤色器来限制选择.
  • 您以前没有知识.在这种情况下,事情会变得更加复杂.我倾向于说没有用的LED都应具有相同的颜色,并且状态LED通常会闪烁.这意味着通过向该方法添加学习步骤,您可能能够看到实际上必须选择哪些LED才有用.

希望这会带来更多思考的食物

Hope this brings some more food for thoughts

这篇关于从图像检测LED对象状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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