【发布时间】:2020-12-31 09:46:52
【问题描述】:
我想填充面具的某个区域。我的代码看起来像这样 =
if __name__ == "__main__":
while 2>1:
with mss.mss() as sct:
monitor = {"top": 360, "left": 810, "width": 650, "height": 475}
output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)
# Grab the data
sct_img = np.array(sct.grab(monitor))
shap = sct_img.shape
mask = np.zeros_like(sct_img)
pts = np.array([[1, 3], [4, 8], [1, 9]], np.int32)
cv2.fillPoly(mask, pts, 255)
cv2.imshow("OPENCV/NUMPY normal", mask)
if cv2.waitKey(25) & 0xFF == ord("q"):
cv2.destroyAllWindows()
break
我得到错误:
cv2.fillPoly(mask, pts, 255) cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\imgproc\src\drawing.cpp:2395: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'cv::fillPoly'
【问题讨论】:
-
尝试 np.uint8 代替 np.int32