I wanted to know if anyone knows of a way to use open cv in Java to view a part of a screen and detect significant change in color, for instance, if the starting color is [r = 112,g = 112,b = 112] and becomes this [r = 43,g = 42,b = 41], or if the starting color is more grey and suddenly gains color and becomes more red, green, or blue.

1 Answers

0
Vardan Agarwal On

I did not correctly understand your question but I think you want to detect changes in color. I have written the code in python so sorry for that.

test image used

I have used this image as my test image.

original = cv2.imread('inner.png')
img = cv2.cvtColor(original, cv2.COLOR_RGB2GRAY) # convert to grayscale
ret,thresh1 = cv2.threshold(img, 150, 255, cv2.THRESH_BINARY) #thresholding image
ret,thresh2 = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY) #thresholding image with a different range
thresh1 = cv2.Canny(thresh1, 10, 255) #applying edge detection
thresh2 = cv2.Canny(thresh2, 10, 255) #applying edge detection
im, contours1, _ = cv2.findContours(thresh1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) #finding contours
im, contours2, _ = cv2.findContours(thresh2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) #finding contours
cv2.drawContours(original, contours1, -1, (0, 255, 255), 3) #drawing contours on original image
cv2.drawContours(original, contours2, -1, (0, 255, 255), 3) #drawing contours on original image
cv2.imshow('image', original)
cv2.waitKey(0)
cv2.destroyAllWindows()

This code gives the result.

enter image description here