gpt4 book ai didi

java - 如何查看屏幕某个区域的像素颜色是否发生变化?

转载 作者:行者123 更新时间:2023-12-02 05:32:09 25 4
gpt4 key购买 nike

我想知道是否有人知道在 Java 中使用 open cv 来查看屏幕的一部分并检测颜色的显着变化的方法,例如,如果起始颜色是 [r = 112,g = 112,b = 112] 并变为此 [r = 43,g = 42,b = 41],或者如果起始颜色更灰色并突然获得颜色并变得更红、更绿或更蓝。

最佳答案

我没有正确理解你的问题,但我认为你想检测颜色的变化。我已经用 python 编写了代码,对此感到抱歉。

test image used

我已使用此图像作为我的测试图像。

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()

这段代码给出了结果。

enter image description here

关于java - 如何查看屏幕某个区域的像素颜色是否发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56196022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com