User Tools

Site Tools


projects:farmrobot:nvidia-jetson-tx1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projects:farmrobot:nvidia-jetson-tx1 [2021/01/03 21:07]
jason
projects:farmrobot:nvidia-jetson-tx1 [2021/01/10 19:28] (current)
jason
Line 6: Line 6:
 | ''jetson''  | ''jetson''    | | ''jetson''  | ''jetson''    |
  
-===== Stats =====+===== Running YOLOv5 with on-board CSI camera or external USB camera (Motion JPEG) ===== 
 + 
 +Arguments for NVIDIA's GStreamer camera pipeline depend on supported camera formats. 
 + 
 +To start YOLOv5's detection, run the following command and provide the GStreamer camera pipeline as the source: 
 + 
 +<file shell> 
 +# On-board CSI camera 
 +python3.8 detect.py --source "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)2592, height=(int)1458, framerate=(fraction)30/1, format=(string)NV12 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink" 
 + 
 +# External USB camera (Motion JPEG) 
 +python3.8 detect.py --source "v4l2src device=/dev/video1 ! image/jpeg, width=(int)1920, height=(int)1080, framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink" 
 +</file> 
 + 
 +<WRAP important> 
 +In the example above, the on-board CSI camera is represented by ''/dev/video0'' and the external USB camera by ''/dev/video1''. Depending on the configuration of connected cameras, those paths might differ. 
 +</WRAP> 
 + 
 +<WRAP info> 
 +See this [[https://stackoverflow.com/questions/65638140/create-pipeline-for-gstreamer-for-usb-camera-mjpg-format|Stack Overflow post]]. 
 +</WRAP> 
 + 
 +===== Current data ===== 
 + 
 +==== On-board camera ==== 
 + 
 +<file shell> 
 +sudo apt install -y v4l-utils 
 +</file> 
 + 
 +<file shell> 
 +v4l2-ctl -d /dev/video0 --list-formats-ext 
 + 
 +ioctl: VIDIOC_ENUM_FMT 
 +        Index       : 0 
 +        Type        : Video Capture 
 +        Pixel Format: 'BG10' 
 +        Name        : 10-bit Bayer BGBG/GRGR 
 +                Size: Discrete 2592x1944 
 +                        Interval: Discrete 0.033s (30.000 fps) 
 +                Size: Discrete 2592x1458 
 +                        Interval: Discrete 0.033s (30.000 fps) 
 +                Size: Discrete 1280x720 
 +                        Interval: Discrete 0.008s (120.000 fps) 
 +</file> 
 + 
 +{{:projects:farmrobot:img_20210106_183252.jpg?400|}} 
 +{{:projects:farmrobot:img_20210106_183318.jpg?400|}} 
 +{{:projects:farmrobot:img_20210106_183359.jpg?400|}} 
 +{{:projects:farmrobot:img_20210106_183426.jpg?400|}} 
 +{{:projects:farmrobot:img_20210107_175211.jpg?400|}} 
 + 
 +==== Measurements ====
  
 YOLOv5 (street.mp4): 11/12 fps (~0.086s +- 0.005s per frame) YOLOv5 (street.mp4): 11/12 fps (~0.086s +- 0.005s per frame)
  
-{{:projects:farmrobot:img_20201228_205724.jpg?nolink&400|}}+{{:projects:farmrobot:img_20201228_205724.jpg?600|}}
  
 ===== Setup ===== ===== Setup =====
Line 149: Line 201:
  
 sudo swapon ~/swapfile sudo swapon ~/swapfile
 +</file>
 +
 +==== Building OpenCV from source (with GStreamer support) ====
 +
 +Because [[https://opencv.org/|OpenCV]] does not support NVIDIA's GStreamer software by default, it has to be built from source with GStreamer support enabled.
 +
 +<WRAP info>
 +[[https://developer.download.nvidia.com/embedded/L4T/r32_Release_v1.0/Docs/Accelerated_GStreamer_User_Guide.pdf?9N7jupgUlde8JwGYrJQO434MhxI7ZlJf8jfNYE-eI9uMBECrQldp3897ijsNYjnxBWWiY8OtUVfEKr4cLQNUyoevaUfjyXksRnT__8EmmhKVHWYbRK7-6NdQOQ8jJtev1-0IhZKyQ1rxjQh2_35qOofKmyWN8kH58nZHAQyVRax9kaD5tXY|Accelerated GStreamer User Guide]]
 +</WRAP>
 +
 +To get started, install the packages that OpenCV with GStreamer support depends on:
 +
 +<file shell>
 +sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
 +</file>
 +
 +Then, install [[https://numpy.org/|NumPy]] as OpenCV also depends on it:
 +
 +<file shell>
 +python3.8 -m pip install --user numpy
 +</file>
 +
 +After all dependencies are installed, go ahead and clone the [[https://github.com/opencv/opencv|OpenCV GitHub repository]], change into its directory and checkout the latest version branch:
 +
 +<file shell>
 +git clone https://github.com/opencv/opencv.git
 +
 +cd opencv
 +
 +# General
 +git checkout <version>
 +
 +# OpenCV 4.5.0
 +git checkout 4.5.0
 +</file>
 +
 +Before you can start building OpenCV, create a ''/build`'' directory and change into it:
 +
 +<file shell>
 +mkdir build
 +
 +cd build
 +</file>
 +
 +Then, use ''cmake'' to prepare the build with the correct settings:
 +
 +<file shell>
 +cmake -D CMAKE_BUILD_TYPE=RELEASE \
 +-D INSTALL_PYTHON_EXAMPLES=ON \
 +-D INSTALL_C_EXAMPLES=OFF \
 +-D PYTHON_EXECUTABLE=$(which python3.8) \
 +-D BUILD_opencv_python2=OFF \
 +-D CMAKE_INSTALL_PREFIX=$(python3.8 -c “import sys; print(sys.prefix)”) \
 +-D PYTHON3_EXECUTABLE=$(which python3.8) \
 +-D PYTHON3_INCLUDE_DIR=$(python3.8 -c “from distutils.sysconfig import get_python_inc; print(get_python_inc())”) \
 +-D PYTHON3_PACKAGES_PATH=$(python3.8 -c “from site import getsitepackages; print(getsitepackages())”) \
 +-D WITH_GSTREAMER=ON \
 +-D BUILD_EXAMPLES=ON ..
 +</file>
 +
 +It is important to check the resulting output. Check if the output contains the following important bits:
 +
 +<file shell>
 +...
 +
 +GStreamer:         YES (<version>)
 +
 +...
 +
 +Python3:
 +  Interpreter:     <path>
 +  Libraries:       <path>
 +  numpy:           <path>
 +  install path:    <path>
 +
 +...
 +</file>
 +
 +If everything went well, you can go ahead and build it:
 +
 +<file shell>
 +sudo make -j$(nproc)
 +</file>
 +
 +When the build is finished, install it:
 +
 +<file shell>
 +sudo make install
 </file> </file>
  
Line 241: Line 381:
 </file> </file>
  
-Then change the directory into the local repository and clone the official [[https://github.com/ultralytics/yolov5|YOLOv5]] GitHub repository:+Then change the directory into the local repository and clone the official [[https://github.com/ultralytics/yolov5|YOLOv5 GitHub repository]]:
  
 <file shell> <file shell>
projects/farmrobot/nvidia-jetson-tx1.1609708050.txt.gz · Last modified: 2021/01/07 16:26 (external edit)