![](/img/trans.png)
[英]error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
[英]Problem with this error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize' OpenCV
运行 resize function 行后,我遇到了这个错误:
import cv2
import numpy as np
import matplotlib.pyplot as plt
net = cv2.dnn.readNetFromDarknet('yolov3_custom.cfg', 'yolov3_custom_last.weights')
cap = cv2.VideoCapture(0)
while 1:
_, img = cap.read()
img = cv2.resize(img,(1280,720))
hight,width,_ = img.shape
blob = cv2.dnn.blobFromImage(img, 1/255,(416,416), (0,0,0), swapRB = True,crop= False)
此错误是因为没有捕获任何帧。
请试试
cap = cv2.VideoCapture(1)
问题是没有这样捕获的帧,没有可调整大小的图像。 为了确保您的网络摄像头实际上正在捕获,请尝试以下操作:
cap = cv2.VideoCapture(0)
while 1:
ret, img = cap.read()
if not ret:
print("no frame captured")
exit()
img = cv2.resize(img,(1280,720))
#continue processing
然后测试以确保您的网络摄像头工作正常,或者如果您有多个网络摄像头,请尝试使用另一个索引来初始化“VideoCapture”
cap = VideoCapture(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.