我想知道是否有人知道在Java中使用open cv
来查看屏幕的一部分并检测颜色的显着变化的方法,例如,起始颜色是否为[r = 112,g = 112,b = 112]
以及变成[r = 43,g = 42,b = 41]
,或者如果起始颜色更灰并且突然变色,变得更红,绿或蓝。
答案 0 :(得分:0)
我无法正确理解您的问题,但我认为您想检测颜色的变化。我已经用python编写了代码,对此感到抱歉。
我已将此图像用作测试图像。
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()
此代码给出结果。