Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of V4L2+OpenCV3.1 Reading USB camera Image in MJPG format and Real-time display in Jetson TX1 Development

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the Jetson TX1 development of V4L2+OpenCV3.1 to MJPG format to read USB camera images and real-time display example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1 preface

Blogger's 800W HD camera:

As can be seen from the above two images, the YUV2 output format of the camera has only one 640x480resolution, while the output format MJPG has multiple resolutions. If you want to achieve high-definition acquisition, you need to collect through the MJPG format.

The output format of the camera can be YUY2, MJPG, etc. For the camera whose output format is YUV2, you can use the nvcamerasrc in the previous note and directly call Gstreamer to capture the video image. As for the camera with output format MJPG, because the blogger doesn't know much about Gstreamer, he decides to use V4L2+OpenCV3.1 for image acquisition.

2 preliminary knowledge 2.1 basic V4L2

For the content of this part, you can see this Daniel's blog: http://www.cnblogs.com/surpassal/archive/2012/12/19/zed_webcam_lab1.html

Because the MJPG capture format is used, the pixelformat of the camera frame format needs to be set to V4L2_PIX_FMT_MJPEG when the V4L2 device is initialized:

2.2 OpenCV image decoding

You can use cvDecodeImage to decode the image, and buf is the buffer that saves the image. The iscolor parameter is 0, which is decoded into grayscale image and the parameter is 1, which is decoded into color image. Here we set the iscolor parameter to 1.

The code is as follows:

3 Compiler 3.1 overall code

Because the code is long, it will affect the appearance. You can download the whole code from my Github:

URL: https://github.com/Jack-Cherish/VideoCapture/blob/master/capture.cpp

Welcome follow, star!

3.2 compile and run

The running environment needs to be configured with OpenCV3.1. For more information on configuration tutorials, please see http://blog.csdn.net/c406495762/article/details/72302980

Add the environment variable at the end of ~ / .bashrc (my OpenCV3.1 is installed under / home/ubuntu/opencv-3.1.0, which needs to be changed to the path of your own OpenCV3.1):

Export LD_LIBRARY_PATH=/home/ubuntu/opencv-3.1.0/lib:$LD_LIBRARY_PATHexport PKG_CONFIG_PATH=/home/ubuntu/opencv-3.1.0/lib/pkgconfig:$PKG_CONFIG_PATH

To make the added environment variable effective:

Source / .bashrc

Copy the program into TX1 and compile with the following instructions (my OpenCV3.1 is installed under / home/ubuntu/opencv-3.1.0, which needs to be changed to the path of your own OpenCV3.1):

Gmail +-o capture-I / home/ubuntu/opencv-3.1.0/include-O2-g-Wall capture.cpp-L / home/ubuntu/opencv-3.1.0/lib-lopencv_core-lopencv_imgproc-lopencv_ flann-lopencv_ imgcodecs-lopencv_videoio-lopencv_highgui-lopencv_ml-lopencv_video-lopencv_objdetect-lopencv_photo-lopencv_features2d-lopencv_calib3d-lopencv_stitching-lopencv_videostab-lopencv_shape-lopencv_cudaobjdetect-lopencv_cudawarping-lopencv_cudaimgproc4 Operation Row result video dev: / dev/video0Driver Name:uvcvideoCard Name:RecordexUSABus info:usb-tegra-xhci-3.3Driver Version:3.10.96Support format:1.YUV 4:2:2 (YUYV) 2.MJPEGDefault rec: left:0top:0width:1920height:1080Current data format information: width:1920height:1080Used time is 185.864 msUsed time is 56.2118 msUsed time is 17.0305 msUsed time is 14.5383 msUsed time is 43.1591 msUsed time is 32.4903 msUsed time is 28.6098 msUsed time is 20 .398 msUsed time is 33.6233 msUsed time is 23.8306 ms Thank you for reading this article carefully I hope the article "sample analysis of V4L2+OpenCV3.1 reading USB camera images in MJPG format and real-time display by V4L2+OpenCV3.1 in Jetson TX1 development" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report