# OpenCV Java How can I find red lined Rectangles from 12 rectangles.

I am running into a very unique problem statement. I have an image which will have 12 led lights and a few out of them will glow as red. After trying out multiple algorithms, I have reached till this stage (See Image Below ) from an RGB image taken from the camera.

I have reached to this image by applying this algorithms -

```
Mat detectedEdges = new Mat(ImageMat.rows(), ImageMat.cols(), CvType.CV_8UC1);
//Imgproc.blur(ImageMatNew, detectedEdges, new Size(3,3));
Imgproc.GaussianBlur(ImageMatNew, detectedEdges, new Size(3,3), 7);
Imgproc.Canny(detectedEdges, detectedEdges, 70, 70 * 3, 3, false);
Imgproc.adaptiveThreshold(detectedEdges, detectedEdges, 200,Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C , Imgproc.THRESH_BINARY_INV,3, 7);
Imgproc.Canny(detectedEdges, detectedEdges, 10, 10 * 7, 7, true);
```

Now From here, I am completely lost. I have searched all over places and tried multiple approaches. So My problem state goes like this;

In this Image, there will be always 12 rectangles. Few rectangles will be red single lined eclosed and others will be black double lined eclosed rectangles. I have to find these single lined red enclosed rectangles and their number from top to bottom or bottom to top between 1-12.

I was trying with contours but I don't think contours are going to solve my any problem. Because I tried with Contour Area but here I can match the area or even can't approximate the area so that I can iterate from top to bottom.

I am stuck in this problem since a week. any slight hint or approach will help me Thanks in Advance.