Example of using YOLO v4 with OpenCV, C++ and Python

Overview

yolov4-opencv-cpp-python

Example of performing inference with Darknet YOLO V4, OpenCV 4.4.0 DNN, C++ and Python

Looking for YOLO V5 OpenCV C++/Python inference? Check this repository

Prerequisites

Make sure you have already on your system:

  • OpenCV 4.0+
  • Python 3.7+
  • Any modern Linux OS (tested on Ubuntu 20.04)
  • GCC 9.0+

Running the python script

The python code is here.

git clone https://github.com/doleron/yolov4-opencv-cpp-python.git
cd yolov4-opencv-cpp-python
python python/yolo.py 

If your machine/OpenCV install are CUDA capable you can try out running using the GPU:

git clone https://github.com/doleron/yolov4-opencv-cpp-python.git
cd yolov4-opencv-cpp-python
python python/yolo.py cuda

Running the C++ program

The C++ code is here.

git clone https://github.com/doleron/yolov4-opencv-cpp-python.git
cd yolov4-opencv-cpp-python
g++ -O3 cpp/yolo.cpp -o yolo_example `pkg-config --cflags --libs opencv4`
./yolo_example

Or using CUDA if available:

git clone https://github.com/doleron/yolov4-opencv-cpp-python.git
cd yolov4-opencv-cpp-python
g++ -O3 cpp/yolo.cpp -o yolo_example `pkg-config --cflags --libs opencv4`
./yolo_example cuda

running the examples

PS.: Video sample from https://www.youtube.com/watch?v=NyLF8nHIquM

Which YOLO version should I use?

This repository uses YOLO V4 but it is not the only YOLO version out there. You can read this article to learn more about YOLO versions and choose the more suitable one for you.

You might also like...
GPU PyTorch TOP in TouchDesigner with CUDA-enabled OpenCV

PyTorchTOP This project demonstrates how to use OpenCV with CUDA modules and PyTorch/LibTorch in a TouchDesigner Custom Operator. Building this projec

Libcamera with OpenCV in Raspberry Pi 64 bit Bullseye

Libcamera OpenCV RPi Bullseye 64OS Libcamera + OpenCV on a Raspberry Pi 4 with 64-bit Bullseye OS In the new Debian 11, Bullseye, you can only capture

liteCV is greater than OpenCV :)

liteCV liteCV is lightweight image processing library for C++11. Unlike OpenCV, liteCV must be SIMPLE. Unlike OpenCV, liteCV must be INDEPENDENCE. Ach

Helper Class for Deep Learning Inference Frameworks: TensorFlow Lite, TensorRT, OpenCV, ncnn, MNN, SNPE, Arm NN, NNAbla
Helper Class for Deep Learning Inference Frameworks: TensorFlow Lite, TensorRT, OpenCV, ncnn, MNN, SNPE, Arm NN, NNAbla

InferenceHelper This is a helper class for deep learning frameworks especially for inference This class provides an interface to use various deep lear

This is a small example project, that showcases the possibility of using a surrogate model to estimate the drag coefficient of arbitrary triangles.
This is a small example project, that showcases the possibility of using a surrogate model to estimate the drag coefficient of arbitrary triangles.

flowAroundTriangles This is a small example project, that showcases the possibility of using a surrogate model to estimate the drag coefficient of arb

CUDA Custom Buffers and example blocks
CUDA Custom Buffers and example blocks

gr-cuda CUDA Support for GNU Radio using the custom buffer changes introduced in GR 3.10. Custom buffers for CUDA-enabled hardware are provided that c

Android example to get the rgb and disparity images from the OAK-D device connected to a phone.

depthai-android-jni-example (WIP) Android example to get the rgb and disparity images from the OAK-D device connected to a phone. DepthaiAndroidFast.m

Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library,  for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow
Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow

eXtreme Gradient Boosting Community | Documentation | Resources | Contributors | Release Notes XGBoost is an optimized distributed gradient boosting l

Comments
  • Inference speed on python vs cpp ?

    Inference speed on python vs cpp ?

    Hi, do you have any comparison for the inference speed between cpp & python with batch 1 ? It would be very helpful if you have any such metrics.

    Have a good day!

    opened by adesgautam 1
Owner
ars longa, vita brevis
null
Python Inference Script is a Python package that enables developers to author machine learning workflows in Python and deploy without Python.

Python Inference Script(PyIS) Python Inference Script is a Python package that enables developers to author machine learning workflows in Python and d

Microsoft 13 Nov 4, 2022
License plate parsing using Darknet and YOLO

DarkPlate Note that DarkPlate by itself is not a complete software project. The intended purpose was to create a simple project showing how to use Dar

Stéphane Charette 35 Dec 9, 2022
(ROS) YOLO detection with TensorRT, utilizing tkDNN

tkDNN-ROS YOLO object detection with ROS and TensorRT using tkDNN Currently, only YOLO is supported. Comparison of performance and other YOLO implemen

EungChang-Mason-Lee 7 Dec 10, 2022
YOLO v5 ONNX Runtime C++ inference code.

yolov5-onnxruntime C++ YOLO v5 ONNX Runtime inference code for object detection. Dependecies: OpenCV 4.5+ ONNXRuntime 1.7+ OS: Windows 10 or Ubuntu 20

null 99 Dec 30, 2022
C Language version for yolo in risc-v

RISC-V C-Embedding Yolo 基于Yolo v2的蜂鸟e203 RISC-V部署代码,其中的加速器由队伍中负责硬件的人使用Verilog编写(暂不提供),并在硬件提供的C API上搭建了yolo的部署代码。其中,加速器硬件模块暂由c编写的神经网络加速器模拟器来代替。 网络实现了人脸

Ling Zhang 2 Jul 19, 2022
Mixed reality VR laser tag using Oculus Quest 2 and OAK-D depth cameras. First prize winner for North America region in OpenCV AI Competition 2021.

Mixed Reality Laser Tag Copyright 2021 Bart Trzynadlowski Overview This is the source code to my Mixed Reality Laser Tag project, which won first priz

null 34 Jun 3, 2022
A simple facial recognition script using OpenCV's FaceRecognizer module implemented in C++

Local Binary Patterns Histogram Recognizer A proyect that implements the LBPHRecognizer class of the OpenCV library to determine if a detected face co

Pablo Agustín Ortega-Kral 0 Jan 18, 2022
The SCRFD face detection, depends on ncnn library and opencv

The SCRFD face detection, depends on ncnn library and opencv

null 157 Jan 5, 2023
This is a sample ncnn android project, it depends on ncnn library and opencv

This is a sample ncnn android project, it depends on ncnn library and opencv

null 248 Jan 6, 2023
cvnp: pybind11 casts between numpy and OpenCV, possibly with shared memory

cvnp: pybind11 casts and transformers between numpy and OpenCV, possibly with shared memory Explicit transformers between cv::Mat / cv::Matx and numpy

Pascal Thomet 19 Jan 5, 2023