gpt4 book ai didi

python - 在函数 'inRange'中(-215:断言失败)! _src.empty()

转载 作者:行者123 更新时间:2023-12-02 17:18:45 28 4
gpt4 key购买 nike

我目前正在使用openCV进行小型项目,并且收到此错误消息:

Traceback (most recent call last):
File "main.py", line 115, in <module>
value = cv2.inRange(roi, (0,0,0), (255, 255, 75))
cv2.error: OpenCV(4.1.2) /root/opencv/opencv-4.1.2/modules/core/src/arithm.cpp:1726: error: (-215:Assertion failed) ! _src.empty() in function 'inRange'

我已经在Internet上进行了一些研究,但是还没有找到适合我的解决方案。当我更改感兴趣区域(短roi)的坐标时,总是会发生错误。
代码(至少最重要的部分):
roi= (50, 270, 150, 192)

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

image = frame.array
cut = image[roi[0]:roi[1]][roi[2]:roi[3]]
value = cv2.inRange(cut, (0,0,0), (255, 255, 75))
rawCapture.truncate(0)

最佳答案

确保按正确的顺序 slice 轴,因为
frame.array返回形状为(y,x,3)的numpy数组。

After flush() is called, this attribute contains the frame’s data as a multi-dimensional numpy array. This is typically organized with the dimensions (rows, columns, plane). Hence, an RGB image with dimensions x and y would produce an array with shape (y, x, 3).Make sure your axes slice are in the right order

#RGB Image 640x480
img = np.ones((480,640,3))

roi= (500, 600, 150, 192)

cut = img[roi[0]:roi[1]][roi[2]:roi[3]]
value = cv2.inRange(cut, (0,0,0), (255, 255, 75))

#error: (-215:Assertion failed) ! _src.empty() in function 'cv::inRange'

关于python - 在函数 'inRange'中(-215:断言失败)! _src.empty(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63316222/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com