Jetson TX1使用usb camera采集图像 (1)
使用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 nvcamerasrc, nvvidconv and omxh264dec could be found in this document.
How to run the Tegra camera sample code:
- Download the
tegra-cam.pysource 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.
Jetson TX1使用usb camera采集图像 (1)的更多相关文章
- Jetson TX1使用usb camera采集图像 (2)
该方法只启动usb摄像头 import cv2 import numpy import matplotlib.pyplot as plot class Camera: cap = cv2.VideoC ...
- Camera 采集图像的方法
使用 Camera 采集图像, 实现步骤如下: 需要权限: android.permission.CAMERA android.permission.WRITE_EXTERNAL_STORAGE // ...
- 【Xilinx-Petalinux学习】-06-OpenCV通过USB摄像头采集图像。
占位, 实现USB摄像头的图像采集与保存
- 基于英伟达Jetson TX1的GPU处理平台
基于英伟达Jetson TX1 GPU的HDMI图像输入的深度学习套件 [309] 本平台基于英伟达的Jetson TX1视觉计算的全功能开发板,配合本公司研发的HDMI输入图像采集板:Jetson ...
- camera按键采集图像及waitKey的用法(转)
源: camera按键采集图像及waitKey的用法
- camera按键采集图像及waitKey的用法
前言 项目需要通过摄像头采集图像并保存,主要是用于后续的摄像头标定.实现过程其实很简单,需要注意一些细节. 系统环境 系统版本:ubuntu16.04:opencv版本:opencv2.4.13:编程 ...
- [转]Jetson TX1 开发教程(1)配置与刷机
开箱 Jetson TX1是英伟达公司新出的GPU开发板,拥有世界上先进的嵌入式视觉计算系统,提供高性能.新技术和极佳的开发平台.在进行配置和刷机工作之前,先来一张全家福: 可以看到,Jetson T ...
- 【并行计算-CUDA开发】 NVIDIA Jetson TX1
概述 NVIDIA Jetson TX1是计算机视觉系统的SoM(system-on-module)解决方案.它组合了最新的NVIDIAMaxwell GPU架构,其具有ARM Cortex-A57 ...
- ffmpeg从USB摄像头采集一张原始图片(转)
本文讲解使用ffmpeg从USB摄像头中采集一帧数据并写入文件保存,测试平台使用全志A20平台,其他平台修改交叉工具链即可移植.开发环境使用eclipse+CDT.交叉工具链使用arm-Linux-g ...
随机推荐
- 基于 DataLakeAnalytics 做跨地域的数据分析
在阿里云上,很多客户的应用都是多地域部署的, 比如在北京(cn-beijing)的地域部署一个应用让北方的客户访问快一点,同时在杭州(cn-hangzhou)地域部署一份让南方的客户访问快一点.多地域 ...
- 痞子衡嵌入式:飞思卡尔Kinetis系列MCU开发那些事 - 索引
大家好,我是痞子衡,是正经搞技术的痞子.本系列痞子衡给大家介绍的是飞思卡尔Kinetis系列微控制器相关知识. 飞思卡尔半导体(现恩智浦半导体)于2010年开始推出的Kinetis系列昭示着ARM C ...
- k8s健康检查(七)--技术流ken
默认的健康检查 强大的自愈能力是 Kubernetes 这类容器编排引擎的一个重要特性.自愈的默认实现方式是自动重启发生故障的容器.除此之外,用户还可以利用 Liveness 和 Readiness ...
- 每周分享五个 PyCharm 使用技巧(二)
这是 「PyCharm 技巧分享」系列的第二篇分享.由于上一篇文章得到了大家的一些赞同,所以今天又来给大家推荐一些我平时自己有用的小技巧,大家择需所取即可. 先声明下,并不保证对所有的人都是有帮助的, ...
- iOS weak底层实现原理
今年年底做了很多决定,离开工作三年的深圳,来到了上海,发现深圳和上海在苹果这方面还是差距有点大的,上海的市场8成使用swift编程,而深圳8成的使用OC,这点还是比较让准备来上海打拼的苹果工程师有点小 ...
- python基础之逻辑运算符
python逻辑运算符: ①and ‘与’ 总结: 如果and左边为False,则直接返回左边的结果(False) 如果and左边为True,则返回的结果取决于右边的数值 ②or ‘或’ 总结: 如果 ...
- nginx系列10:通过upstream模块选择上游服务器和负载均衡策略round-robin
upstream模块的使用方法 1,使用upstream和server指令来选择上游服务器 这两个指令的语法如下图: 示例: 2,对上游服务使用keepalive长连接 负载均衡策略round-rob ...
- Java 单例(Singleton)模式
一.什么是单例模式: 单例模式是一种确保了一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.被实例化的类称为单例类. 二.单例模式的特点: 单例类只有一个实例. 单例类必须自行创建自己唯一的 ...
- Vue.js实现后台菜单切换
因为刚初学Vue.js,暂时遇到以下问题,待之后解决 点击父节点,怎么隐藏显示子节点 点击父节点或子节点,切换li的class="active" iframe怎么自适应高度 思路 ...
- Web API 持续集成:PostMan+Newman+Jenkins(图文讲解)
本文由葡萄城技术团队于博客园原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 上篇文章我们已经完成了API测试工具选型,接下来是一系列周期性的开发 ...