O'Reilly logo

Learn OpenCV 4 by Building Projects - Second Edition by Prateek Joshi, Vinicius G. Mendonca, David Millan Escriva

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Importing YOLO into OpenCV

The deep learning OpenCV module is found under the opencv2/dnn.hpp header, which we have to include in our source header and in cv::dnn namespace.

Then our header for OpenCV must look like this:

...#include <opencv2/core.hpp>#include <opencv2/dnn.hpp>#include <opencv2/imgproc.hpp>#include <opencv2/highgui.hpp>using namespace cv;using namespace dnn;...

The first thing we have to do is import the COCO name's vocabulary, which is in the coco.names file. This file is a plaintext file that contains one class category per line, and is ordered in the same way as the confidence results. Then we are going to read each line of this file and store it in a vector of strings, called classes:

... int main(int argc, char** argv) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required