有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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


共 (1) 个答案

  1. # 1 楼答案

    我没有正确理解您的问题,但我认为您希望检测颜色的变化。我已经用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