Jetson nano笔记——OpenCV报错 [ WARN:[email protected]] GStreamer warning: GStreamer: pipeline have not been created

问题描述

   笔者在桌面级设备上训练了一个视频信号处理模型,使用Pytorch,Torchvision,OpenCV等外部库。前向推导程序在桌面级设备Linux和Windows系统上均运行良好,无报错。

   最近希望将这个模型移植到Jetson nano上,以增强移动性来扩展应用场景。

   Jetson nano 环境概要:

  1. Python==3.6 (conda virual env)
  2. torch==1.11.0, torchvision==0.12.0, opencv-python==4.11.0.86.

   在解决了程序所需的外部库的安装后,发现运行前向推导程序时,出现了如下报错:

Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
[ WARN:0@13.696] global cap_gstreamer.cpp:2830 handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module qtdemux0 reported: Internal data stream error.
[ WARN:0@13.708] global cap_gstreamer.cpp:1698 open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@13.708] global cap_gstreamer.cpp:1173 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

   最终,该报错导致的结果是:cv2.VideoCapture()语句无法正常运行,即无法调取Jetson nano的摄像头,也无法读取本地mp4或者avi文件。

   这个代码在桌面端运行良好,无任何报错或警告,因此,初步确定不是代码的问题,可能是Jetson nano中OpenCV外部库有关GStreamer的依赖文件缺失。

解决方案

  1. 确认Jetson nano是否已安装GStreamer-1.0库;这个库可能在标准的Ubuntu系统中自带,但在Jetson系统中未安装。
gst-inspect-1.0 --version

   笔者的系统报了“Command not found”的错误,看来猜想是对的,需要安装GStreamer-1.0库。

  1. 依次在Terminal中输入以下命令:
sudo apt-get update
sudo apt-get install gstreamer1.0-tools gstreamer1.0-alsa \
     gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
     gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
     gstreamer1.0-libav
sudo apt-get install libgstreamer1.0-dev \
     libgstreamer-plugins-base1.0-dev \
     libgstreamer-plugins-good1.0-dev \
     libgstreamer-plugins-bad1.0-dev

   此步骤会弹出大量提示信息,只要没有ERROR就不用管。

  1. 检验是否安装成功:
gst-inspect-1.0 --version

   出现如下信息,则说明已经安装成功。

gst-launch-1.0 version 1.14.5
GStreamer 1.14.5
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0
  1. 再跑一遍包含OpenCV的代码,有一条警告,但是已经没有报错,程序正常运行。

附件:测试程序

import cv2

test_method = 'file'

if test_method == 'file':
	# 使用视频文件路径来打开视频文件
	cap = cv2.VideoCapture('path_to_your_video_file.avi')
else:
	# 使用 V4L2 后端打开摄像头
	cap = cv2.VideoCapture(0, cv2.CAP_V4L2)

# 检查视频是否成功打开
if not cap.isOpened():
    print("Error: Unable to open video file.")
else:
    while True:
        ret, frame = cap.read()
        if not ret:
            print("Error: Failed to read frame or end of video reached.")
            break

        # 显示视频帧
        cv2.imshow("Video", frame)

        # 按 'q' 键退出
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # 释放资源并关闭窗口
    cap.release()
    cv2.destroyAllWindows()

[ WARN:0@6.920] global cap_gstreamer.cpp:2824 cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin: Audio Video Interleave (AVI) demuxer [ WARN:0@6.920] global cap_gstreamer.cpp:2840 cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin0 reported: Your GStreamer installation is missing a plug-in. [ WARN:0@6.921] global cap_gstreamer.cpp:1698 cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline [ WARN:0@6.921] global cap_gstreamer.cpp:1173 cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created [ WARN:0@7.073] global cap_msmf.cpp:935 CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (800x600 @ 49.885) MFVideoFormat_RGB32(codec not found) 视频处理完成,每帧已保存到 ./input 文件夹中。 E:\DHP\code\ruanzhu4.py:109: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. model.load_state_dict(torch.load(args.model)) 0it [00:00, ?it/s] [ WARN:0@7.681] global cap_gstreamer.cpp:2824 cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin: Audio Video Interleave
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值