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/07 16:27]
jason
projects:farmrobot:nvidia-jetson-tx1 [2021/01/10 19:28] (current)
jason
Line 5: Line 5:
 ^ User    ^ Password  ^ ^ User    ^ Password  ^
 | ''jetson''  | ''jetson''    | | ''jetson''  | ''jetson''    |
 +
 +===== 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 ===== ===== Current data =====
Line 34: Line 56:
 {{:projects:farmrobot:img_20210106_183359.jpg?400|}} {{:projects:farmrobot:img_20210106_183359.jpg?400|}}
 {{:projects:farmrobot:img_20210106_183426.jpg?400|}} {{:projects:farmrobot:img_20210106_183426.jpg?400|}}
 +{{:projects:farmrobot:img_20210107_175211.jpg?400|}}
  
 ==== Measurements ==== ==== Measurements ====
Line 178: 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 270: 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.1610036834.txt.gz · Last modified: 2021/01/07 16:27 by jason