【发布时间】:2019-04-18 16:25:24
【问题描述】:
我正在使用 OpenCV 同时读取三个 USB 摄像头的实时视频源。此实时视频馈送被逐帧解析为无人机检测设备的神经网络(使用英特尔 OpenVINO 的神经网络)。
当只使用单个摄像头时,屏幕上会弹出以下警告,但程序似乎仍然可以完美执行:
(python3:4235): GStreamer-CRITICAL **: gst_element_get_state: 断言 'GST_IS_ELEMENT (element)' 失败
但是,当同时使用所有三个摄像头时,终端出现以下错误,程序根本无法运行:
(python3:4041): GStreamer-CRITICAL **: gst_element_get_state: 断言 'GST_IS_ELEMENT (element)' 失败 视频错误:V4L:无法通过索引 0 打开相机 threeCam_droneDetection.py:90: DeprecationWarning: IENetwork 的 from_ir() 方法已弃用。请使用 IENetwork 类构造函数创建有效的 IENetwork 实例 净 = IENetwork.from_ir(模型=model_xml,权重=model_bin) 摄像头不工作
(python3:4041): GStreamer-CRITICAL **: gst_element_get_state: 断言 'GST_IS_ELEMENT (element)' 失败
(python3:4041): GStreamer-CRITICAL **: gst_element_get_state: 断言 'GST_IS_ELEMENT (element)' 失败
我曾尝试使用代码来解决问题,但在使用程序中的所有三个摄像头时,此 GStreamer 错误不断出现。我什至制作了一个单独的程序来简单地调出实时摄像机源(除了用cv2.imshow() 将它们输出到屏幕之外,没有对帧做任何事情,并且这个程序完美地执行。所以我认为我没有出错捕捉无人机检测程序。
以下是我为三摄像头实时无人机检测编写的python脚本中的sn-ps:
#Initialize camera frame dimension variables
camera_width = 244
camera_height = 244
#Initialize 3 cameras and set their frame dimensions
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, camera_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_height)
cap2 = cv2.VideoCapture(1)
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, camera_width)
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_height)
cap3 = cv2.VideoCapture(2)
cap3.set(cv2.CAP_PROP_FRAME_WIDTH, camera_width)
cap3.set(cv2.CAP_PROP_FRAME_HEIGHT, camera_height)
while True:
#Read camera frames and return value (sees if cameras are working)
ret, liveframe = cap.read()
ret2, liveframe2 = cap2.read()
ret3, liveframe3 = cap3.read()
#Breaks script if any of the cameras are not working
if (not ret or not ret2 or not ret3):
print("A camera is not working")
break
# Run inference
res = exec_net.infer(inputs={input_blob: processedImg})
res2 = exec_net.infer(inputs={input_blob: processedImg2})
res3 = exec_net.infer(inputs={input_blob: processedImg3})
# Access the results and get the index of the highest confidence score
output_node_name = list(res.keys())[0]
res = res[output_node_name]
output_node_name2 = list(res2.keys())[0]
res2 = res2[output_node_name2]
output_node_name3 = list(res3.keys())[0]
res3 = res3[output_node_name3]
# Predicted class index.
idx = np.argsort(res[0])[-1]
idx2 = np.argsort(res2[0])[-1]
idx3 = np.argsort(res3[0])[-1]
我非常感谢一些关于如何消除这些 GStreamer 错误并让相机正常工作的建议。谢谢!
【问题讨论】: