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