Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think the contour-based approach is not a good idea.

Try to segment the original image with the inRange function. For best results, first convert the image to the HSV color space.

Another idea would be to use a kind of excess red index by combining the RGB channels: ERI=2*R-G-B. Then threshold this image.

The resulting image should contain only the red colored pixels (which are normally the LEDs). To get rid of the noise, use morphological operators (erosion).

finally, to get the position of the LEDs, use the connected component analysis.

I think the contour-based approach is not a good idea.

Try to segment the original image with the inRange function. For best results, first convert the image to the HSV color space.

Mat ImagHSV, segmented;
Scalar min(0,50,50),max(30,255,255); //adjust these values according to your needs
cvtColor(imageA,imageHSV,COLOR_BGR2HSV);
inRange(imageHSV,min,max,segmented)

Another idea would be to use a kind of excess red index by combining the RGB channels: ERI=2*R-G-B. Then threshold this image.

Mat channels[3],egi,segmented;
int threshold=50;    //set this according to your needs
split(imageA,channels);
egi=2*image[2]-image[1]-image[0];
segmented=egi>threshold;

The resulting image should contain only the red colored pixels (which are normally the LEDs). To get rid of the noise, use morphological operators (erosion).

finally, Finally, to get the position of the LEDs, use the connected component analysis.

NOTE The code samples are for guidance only. They are untested and written in C++. You must understand these functions in order to use the algorithm correctly.

However implementing this algorithm in Java should be straightforward. Refer to the OpenCV documentation for further help and information about the rest of the functions (connected components, morphological operations).

I think the contour-based approach is not a good idea.

Try to segment the original image with the inRange function. For best results, first convert the image to the HSV color space.

Mat ImagHSV, segmented;
Scalar min(0,50,50),max(30,255,255); //adjust these values according to your needs
cvtColor(imageA,imageHSV,COLOR_BGR2HSV);
inRange(imageHSV,min,max,segmented)

See also this tutorial.

Another idea would be to use a kind of excess red index by combining the RGB channels: ERI=2*R-G-B. Then threshold this image.

Mat channels[3],egi,segmented;
int threshold=50;    //set this according to your needs
split(imageA,channels);
egi=2*image[2]-image[1]-image[0];
segmented=egi>threshold;

The resulting image should contain only the red colored pixels (which are normally the LEDs). To get rid of the noise, use morphological operators (erosion).

Finally, to get the position of the LEDs, use the connected component analysis.

NOTE The code samples are for guidance only. They are untested and written in C++. You must understand these functions in order to use the algorithm correctly.

However implementing this algorithm in Java should be straightforward. Refer to the OpenCV documentation for further help and information about the rest of the functions (connected components, morphological operations).