使用python实现

https://jkjung-avt.github.io/tx2-camera-with-python/

How to Capture and Display Camera Video with Python on Jetson TX2

Oct 19, 2017

Quick link: tegra-cam.py

In this post I share how to use python code (with OpenCV) to capture and display camera video on Jetson TX2, including IP CAM, USB webcam and the Jetson onboard camera. This sample code should work on Jetson TX1 as well.

Prerequisite:

  • OpenCV with GStreamer and python support needs to be built and installed on the Jetson TX2. I use opencv-3.4.0 and python3. You can refer to my earlier post for how to build and install OpenCV with python support: How to Install OpenCV (3.4.0) on Jetson TX2.
  • If you’d like to test with an IP CAM, you need to have it set up and know its RTSP URI, e.g. rtsp://admin:XXXXX@192.168.1.64:554.
  • Hook up a USB webcam (I was using Logitech C920) if you’d like to test with it. The USB webcam would usually be instantiated as /dev/video1, since the Jetson onboard camera has occupied /dev/video0.
  • Install gstreamer1.0-plugins-bad-xxx which include the h264parseelement. This is required for decoding H.264 RTSP stream from IP CAM.
$ sudo apt-get install gstreamer1.0-plugins-bad-faad \gstreamer1.0-plugins-bad-videoparsers

Reference:

  • I developed my code based on this canny edge detector sample code.
  • ACCELERATED GSTREAMER FOR TEGRA X2 USER GUIDE: Descriptions of nvcamerasrcnvvidconv and omxh264dec could be found in this document.

How to run the Tegra camera sample code:

  • Download the tegra-cam.py source code from my GitHubGist: https://gist.github.com/jkjung-avt/86b60a7723b97da19f7bfa3cb7d2690e
  • To capture and display video using the Jetson onboard camera, try the following. By default the camera resolution is set to 1920x1080 @ 30fps.
$ python3 tegra-cam.py

  • To use a USB webcam and set video resolution to 1280x720, try the following. The ‘–vid 1’ means using /dev/video1.
$ python3 tegra-cam.py --usb --vid 1 --width 1280 --height 720

  • To use an IP CAM, try the following command, while replacing the last argument with RTSP URI for you own IP CAM.
$ python3 tegra-cam.py --rtsp --uri rtsp://admin:XXXXXX@192.168.1.64:554

Discussions:

The crux of this tegra-cam.py script lies in the GStreamer pipelines I use to call cv.VideoCapture(). In my experience, using nvvidconv to do image scaling and to convert color format to BGRx (note that OpenCV requires BGR as the final output) produces better results in terms of frame rate.

def open_cam_rtsp(uri, width, height, latency):gst_str = ("rtspsrc location={} latency={} ! rtph264depay ! h264parse ! omxh264dec ! ""nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! ""videoconvert ! appsink").format(uri, latency, width, height)return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)def open_cam_usb(dev, width, height):# We want to set width and height here, otherwise we could just do:#     return cv2.VideoCapture(dev)gst_str = ("v4l2src device=/dev/video{} ! ""video/x-raw, width=(int){}, height=(int){}, format=(string)RGB ! ""videoconvert ! appsink").format(dev, width, height)return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER) #该命令在测试时无法启动摄像头,但采用"return cv2.VideoCapture(0)"可以正常显示,I don`t know ???
def open_cam_onboard(width, height): # On versions of L4T previous to L4T 28.1, flip-method=2 # Use Jetson onboard camera gst_str = ("nvcamerasrc ! " "video/x-raw(memory:NVMM), width=(int)2592, height=(int)1458, format=(string)I420, framerate=(fraction)30/1 ! " "nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! " "videoconvert ! appsink").format(width, height) return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

Here’s a screenshot of my Jetson TX2 running tegra-cam.py with a live IP CAM video feed. (I also hooked up a Faster R-CNN model to do human head detection and draw bounding boxes on the captured images here, but the main video capture/display code was the same.)

If you like this post or have any questions, feel free to leave a comment below. Otherwise be sure to also check out my next post How to Capture Camera Video and Do Caffe Inferencing with Python on Jetson TX2, in which I demonstrate how to feed live camera images into a Caffe pipeline for real-time inferencing.

转载于:https://www.cnblogs.com/haiyang21/p/10704308.html

Jetson TX1使用usb camera采集图像 (1)相关推荐

  1. 开发你的酷炫装备 Jetson TX1使用指南

    创客们的最酷"玩具" 智能无人机.自主机器人.智能摄像机.自动驾驶--今年最令硬件创客们着迷的词汇,想必就是这些一线"网红"了.而这些网红的背后,几乎都和计算机 ...

  2. 使用v4l2音、视频协议实现USB摄像头的图像、视频YUV格式采集功能(ubuntu16.04LTS)

    第一感觉是首先得了解v4l2协议,它的功能.以及与之对应的实现逻辑,还有与硬件.操作系统的交互等内容.再试着根据功能逻辑和软硬件交互关系,借助硬件设备,实现基础的功能,如查询设备信息.帧类型等.然后, ...

  3. Python-OpenCV--USB摄像头采集图像并保存到指定文件夹

    一.调用笔记本自带摄像头或者台式机外接USB摄像头实时录像显示,并逐帧保存采集图像到指定的文件夹(目录), 注意:保存量较大,长时间采集记得删除无用的图像. 路径前加"r"和路径后 ...

  4. Jetson TX1 /TX2 对比介绍

    大家好,我是虎哥,经过一段时间的整理,针对TX1/TX2这些看起来已经落伍的产品,如何找到合适的应用场景,我也整体上做了一些了解好调研.现在由于资料很多都比较老了,有些表述也有些前后表述不一,所以这里 ...

  5. NVIDIA嵌入式开发板Jetson TX1教程

    开箱 Jetson TX1(现在已经出了TX2)是英伟达公司新出的GPU开发板,拥有世界上先进的嵌入式视觉计算系统,提供高性能.新技术和极佳的开发平台,之前还出过TK1,鉴于TK1比较小,而且性能不如 ...

  6. Jetson TX1 开发教程(1)--配置与刷机

    开箱 Jetson TX1是英伟达公司新出的GPU开发板,拥有世界上先进的嵌入式视觉计算系统,提供高性能.新技术和极佳的开发平台.在进行配置和刷机工作之前,先来一张全家福: 可以看到,Jetson T ...

  7. 海康工业相机常用参数修改以及使用OpenCV-Python采集图像

    海康工业相机常用参数修改以及使用OpenCV-Python采集图像 一.调节相机参数 1.调节曝光时间 2.修改图像尺寸和像素格式 3.保存参数 二.Python采集成opencv可识别格式,并用op ...

  8. vscode 英伟达tk1_【Codecs系列】之NVIDIA Jetson TX1简介

    DATE: 2019-2-18 参考: https://www.ncnynl.com/archives/201705/1607.html https://blog.csdn.net/q6324266/ ...

  9. 基于GTK的USB视频采集程序

    基于GTK的USB视频采集程序 查了几天的资料,今天终于将USB摄像头测试程序调试成功了.这个测试程序很简单,功能就是将USB摄像头采集的数据显示在屏幕上.写这个程序的目的是熟悉usb摄像头的一些基本 ...

最新文章

  1. 目标跟踪之粒子滤波---Opencv实现粒子滤波算法
  2. 负数分解质因数java_Java经典案例之-“分解质因数”
  3. 装车机器人_智造春天脚步近 青岛这家机器人公司着手打造模块化、标准化技术平台...
  4. DeepMind用ReinforcementLearning玩游戏
  5. 1022 词法分析程序总结
  6. CF1497C k-LCM
  7. soapui 测试soap_使用SoapUI调用不同的安全WCF SOAP服务-基本身份验证,第一部分
  8. 电大计算机应用基础试卷号2007,电大计算机应用基础(试卷版)计算机试卷7.doc...
  9. linux分区概念理解,在linux安装中的分区概念(转)
  10. UIScrollView无法滚动
  11. 听说你想当黑客,我只能帮你到这了
  12. 接口(Api)版本号命名规则
  13. Sybase的安装、配置及使用(五)
  14. STM32F205通过SDIO和SPI读写SD卡文件
  15. 中华石杉Java面试突击第一季笔记三(分布式缓存)
  16. 【Love2d从青铜到王者】第十五篇:Love2d之角度和距离(Angles and distance)
  17. 亚马逊被人差评了怎么办?
  18. 如何解决vmware虚拟机下ubuntu无法连接WiFi问题
  19. java runtime是什么软件_Java SE Runtime Environment (JRE) 运行Java程序的必备软件
  20. Linux Github 使用 ssh 登录及推送 - 一站式教程

热门文章

  1. JAVA数据库第四章上机3_Java第二至第四章上机练习题
  2. cf网络原因服务器无响应,CF由于网络原因连接服务器失败请重试 1033_10136
  3. php mysql切换版本5.7_phpstudy 升级 MySQL版本到MySQL5.7
  4. 联想e480笔记本如何拆屏幕_如何评价 2020 年 10 月 20 日联想发布的小新 Pro14 笔记本?有哪些亮点和槽点?...
  5. 项目启动 ora-00942:_如何解决大型软件项目开发难题?唯快不破!
  6. IDEA设置方法自动显示参数提示
  7. win7安装gtp磁盘_GPT转MBR分区格式安装win7/win10系统教程
  8. 2020.2idea怎么创建html模块_利用idea快速搭建一个项目
  9. idea每次都要配置tomcat_电脑每次开机时间都不对?电脑每次开机都要重新设置时间解决方法...
  10. 2019牛客暑期多校训练营(第五场)- generator 1