我试图让python-opencv运行,但我总是得到这个错误:
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
cv2.error: OpenCV(4.5.4-dev) D:aopencv-pythonopencv-pythonopencvmodulescoresrcmatrix.cpp:466: error: (-215:Assertion failed) _step >= minstep in function 'cv::Mat::Mat'
这个路径部分真的很奇怪"D:aopencv-"我甚至从来没有一个D盘。
这是我的代码(Windows 10, python 3.8, pycharm, pipenv)
import cv2 as cv
import numpy as np
import pyautogui as pg
def make_screenshot(x=0, y=0, x_length=1920, y_length=1080, debug=False):
image = pg.screenshot(region=(x, y, x_length, y_length))
image = np.array(image)
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
if debug:
cv.imshow('test', image)
cv.waitKey()
return image
print(make_screenshot(0, 0, 1, 1, False))
已检查,未成功:
error: (-215:Assertion failed) _step>= minstep in function 'cv::Mat::Mat'
error:(-215:Assertion failed) ! size.empty() in function 'cv::resize'OpenCV
cv2。_src.empty() in function 'cv::cvtColor'
是否需要将其转换为数组?
也可以使用。imread()函数。
image = cv2.imread(image)