【发布时间】:2021-05-13 19:53:47
【问题描述】:
我正在做一个项目,需要用特定颜色识别屏幕中的所有像素,并生成带有输出的二进制数组。
我想知道最有效的方法,谢谢。
我曾尝试使用cv2.inRange,但失败了。这是代码:
import cv2
import numpy
from mss.windows import MSS as mss
sct = mss()
monitor_1 = sct.monitors[1]
color=numpy.array((0, 206, 224),dtype=numpy.uint8)
while True :
screen = numpy.array(sct.grab(monitor_1))
mask = cv2.inRange(screen,color, color) # modify your thresholds
inv_mask = cv2.bitwise_not(mask)
arrow = cv2.bitwise_and(screen, inv_mask)
cv2.imshow('arrow', arrow)
【问题讨论】:
-
我试过了,但一直出错,不知道如何修复它 (
The lower boundary is neither an array of the same size and same type as src, nor a scalar in function 'cv::inRange') -
请发布您正在测试的代码和您的输入图像。
-
这是我的图片i.imgur.com/GkWfZdA.png
-
尝试将颜色阈值定义为数组:
color = numpy.array([0, 206, 224])。你的图像也应该是一个8-bit uint矩阵。