YOLOv5 with OpenCV on Jetson Nano

yolov5 YOLOv5

This article explained how to run the original YOLOv5 on the Jetson Nano, and this article explains how to run YOLOv5 on the Jetson Nano using OpenCV.

Introduce the OpenCV library with CUDA and cuDNN enabled that can be used with python 3.8 by referring to this article.

Once OpenCV is installed, all that remains is to build and run the YOLOv5 application. The following repositories have both C++ and python implementations, but since C++ is faster, we will use that one. See the README for details. Original model in https://github.com/doleron/yolov5-opencv-cpp-python.git doesn’t work properly so fork and fixed https://github.com/otamajakusi/yolov5-opencv-cpp-python.git is used.

git clone https://github.com/otamajakusi/yolov5-opencv-cpp-python.git
cd yolov5-opencv-cpp-python
g++ -O3 cpp/yolo.cpp -o yolo_example `pkg-config --cflags --libs opencv4`
./yolo_example cudaCode language: Bash (bash)

To use the USB camera, apply the following patch

diff --git a/cpp/yolo.cpp b/cpp/yolo.cpp
index c26df9e..2727eaf 100644
--- a/cpp/yolo.cpp
+++ b/cpp/yolo.cpp
@@ -129,7 +129,7 @@ int main(int argc, char **argv)
     std::vector<std::string> class_list = load_class_list();
 
     cv::Mat frame;
-    cv::VideoCapture capture("sample.mp4");
+    cv::VideoCapture capture(0);
     if (!capture.isOpened())
     {
         std::cerr << "Error opening video filen";Code language: Diff (diff)

The FPS seems to be about 6.6. (The video below is a demo from the yolov5-opencv-cpp-python.git repository)

That’s all.

Reference