How to detect color spots in an image using OpenCV?

I am trying to detect if the image (black and white sketch) is painted or not in the room using a mobile camera.

enter image description here

I managed to get this result

enter image description here

using the following code

Mat dest = new Mat (sections[i].rows(),sections[i].cols(),CvType.CV_8UC3);
Mat hsv_image = new Mat (sections[i].rows(),sections[i].cols(),CvType.CV_8UC3);

Imgproc.cvtColor (sections[i],hsv_image,Imgproc.COLOR_BGR2HSV);

List <Mat> rgb = new List<Mat> ();
Core.split (hsv_image, rgb);
Imgproc.equalizeHist (rgb [1], rgb [2]);
Core.merge (rgb, sections[i]);
Imgproc.cvtColor (sections[i], dest, Imgproc.COLOR_HSV2BGR);

Core.split (dest, rgb);

How can I successfully figure out if the image is tinted or not. The color can be any, and it has indoor conditions. Please help me with this as I start with it.

thank

+4
source share
1 answer

Processing color images in HSV color-spaceis a good direction. And I split the channels and found the channel Sgreat. Because it Shas color Saturation(饱和度).

enter image description here

Then threshold Swith threshold 100, you get it. enter image description here

.


@Mark, thresh, . , THRESH_OTSU .

python :

##(1) read into  bgr-space
img = cv2.imread("test.png")

##(2) convert to hsv-space, then split the channels
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)

##(3) threshold the S channel using adaptive method(`THRESH_OTSU`)  
th, threshed = cv2.threshold(s, 100, 255, cv2.THRESH_OTSU|cv2.THRESH_BINARY)

##(4) print the thresh, and save the result
print("Thresh : {}".format(th))
cv2.imwrite("result.png", threshed)


## >>> Thresh : 85.0

enter image description here

:

+12

Source: https://habr.com/ru/post/1689425/


All Articles