【发布时间】:2022-12-20 23:37:29
【问题描述】:
我有一台 Mac,我为 CS GO 创建了我的机器人。我的代码:
import numpy as np
import cv2
from mss import mss
from PIL import Image
bounding_box = {'top': 100, 'left': 0, 'width': 2050, 'height': 600}
#variable sct is the mss() function
sct = mss()
#main function
def screen_record():
while True:
sct_img = sct.grab(bounding_box)
#BGR to HSV
hsv_img = cv2.cvtColor(sct_img, cv2.COLOR_BGR2HSV)
cv2.imshow('screen', np.array(sct_img))
if (cv2.waitKey(1) & 0xFF) == ord('q'):
cv2.destroyAllWindows()
break
错误:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
screen_record()
File "/Users/yuriy/Desktop/AI/videocapture.py", line 23, in screen_record
hsv_img = cv2.cvtColor(sct_img, cv2.COLOR_BGR2HSV)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
> - src is not a numpy array, neither a scalar
> - Expected Ptr<cv::UMat> for argument 'src'
而且,我想将 brg 格式转换为 hsv,因为机器人搜索颜色会更容易。请帮我!
我将尝试在 Google 中搜索,但我没有找到任何东西。
【问题讨论】:
标签: python opencv python-imaging-library mss