问题描述
我用 Yolo 测试了 openCV,它在使用网络摄像头时没有问题。我尝试通过此代码使用来自 RTSP 的视频。
net = cv2.dnn.readNet('yolov3_training_last.weights','yolov3_testing.cfg'
classes = []
with open("classes.txt","r") as f:
classes = f.read().splitlines()
cap = cv2.VideoCapture('rtsp://admin:123456@192.168.10.9:554')
font = cv2.FONT_HERShey_PLAIN
colors = np.random.uniform(0,255,size=(100,3))
while(True):
_,img = cap.read()
height,width,_ = img.shape
blob = cv2.dnn.blobFromImage(img,1/255,(416,416),(0,0),swapRB=True,crop=False)
net.setInput(blob)
output_layers_names = net.getUnconnectedOutLayersNames()
layerOutputs = net.forward(output_layers_names)
Boxes = []
confidences = []
class_ids = []
cv2.imshow('frame',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
当我运行这段代码时,它只显示一张图片,然后它就冻结了。当我在 layerOutputs = net.forward(output_layers_names)
行评论时,程序不会冻结。如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)