mirror of
https://github.com/opencv/opencv.git
synced 2025-06-10 11:03:03 +08:00
Repair: incorrect display of class name
This commit is contained in:
parent
7ae19467b5
commit
df5ec54fb8
58
doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown
Normal file
58
doc/tutorials/dnn/dnn_yolo/dnn_yolo.markdown
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
YOLO DNNs {#tutorial_dnn_yolo}
|
||||||
|
===============================
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
------------
|
||||||
|
|
||||||
|
In this text you will learn how to use opencv_dnn module using yolo_object_detection (Sample of using OpenCV dnn module in real time with device capture, video and image).
|
||||||
|
|
||||||
|
We will demonstrate results of this example on the following picture.
|
||||||
|

|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
VIDEO DEMO:
|
||||||
|
@youtube{NHtRlndE2cg}
|
||||||
|
|
||||||
|
Source Code
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The latest version of sample source code can be downloaded [here](https://github.com/opencv/opencv/blob/master/samples/dnn/yolo_object_detection.cpp).
|
||||||
|
|
||||||
|
@include dnn/yolo_object_detection.cpp
|
||||||
|
|
||||||
|
How to compile in command line with pkg-config
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
@code{.bash}
|
||||||
|
|
||||||
|
# g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` yolo_object_detection.cpp -o yolo_object_detection
|
||||||
|
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
Execute in webcam:
|
||||||
|
|
||||||
|
@code{.bash}
|
||||||
|
|
||||||
|
$ yolo_object_detection -camera_device=0 -cfg=[PATH-TO-DARKNET]/cfg/yolo.cfg -model=[PATH-TO-DARKNET]/yolo.weights -class_names=[PATH-TO-DARKNET]/data/coco.names
|
||||||
|
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
Execute with image:
|
||||||
|
|
||||||
|
@code{.bash}
|
||||||
|
|
||||||
|
$ yolo_object_detection -source=[PATH-IMAGE] -cfg=[PATH-TO-DARKNET]/cfg/yolo.cfg -model=[PATH-TO-DARKNET]/yolo.weights -class_names=[PATH-TO-DARKNET]/data/coco.names
|
||||||
|
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
Execute in video file:
|
||||||
|
|
||||||
|
@code{.bash}
|
||||||
|
|
||||||
|
$ yolo_object_detection -source=[PATH-TO-VIDEO] -cfg=[PATH-TO-DARKNET]/cfg/yolo.cfg -model=[PATH-TO-DARKNET]/yolo.weights -class_names=[PATH-TO-DARKNET]/data/coco.names
|
||||||
|
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
Questions and suggestions email to: Alessandro de Oliveira Faria cabelo@opensuse.org or OpenCV Team.
|
BIN
doc/tutorials/dnn/dnn_yolo/images/yolo.jpg
Normal file
BIN
doc/tutorials/dnn/dnn_yolo/images/yolo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
@ -15,7 +15,7 @@ Deep Neural Networks (dnn module) {#tutorial_table_of_content_dnn}
|
|||||||
|
|
||||||
*Author:* Dmitry Kurtaev
|
*Author:* Dmitry Kurtaev
|
||||||
|
|
||||||
This tutorial guidelines how to run your models in OpenCV deep learning module using Halide language backend
|
This tutorial guidelines how to run your models in OpenCV deep learning module using Halide language backend.
|
||||||
|
|
||||||
- @subpage tutorial_dnn_halide_scheduling
|
- @subpage tutorial_dnn_halide_scheduling
|
||||||
|
|
||||||
@ -24,3 +24,11 @@ Deep Neural Networks (dnn module) {#tutorial_table_of_content_dnn}
|
|||||||
*Author:* Dmitry Kurtaev
|
*Author:* Dmitry Kurtaev
|
||||||
|
|
||||||
In this tutorial we describe the ways to schedule your networks using Halide backend in OpenCV deep learning module.
|
In this tutorial we describe the ways to schedule your networks using Halide backend in OpenCV deep learning module.
|
||||||
|
|
||||||
|
- @subpage tutorial_dnn_yolo
|
||||||
|
|
||||||
|
*Compatibility:* \> OpenCV 3.3.1
|
||||||
|
|
||||||
|
*Author:* Alessandro de Oliveira Faria
|
||||||
|
|
||||||
|
In this tutorial you will learn how to use opencv_dnn module using yolo_object_detection with device capture, video file or image.
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
|
// Brief Sample of using OpenCV dnn module in real time with device capture, video and image.
|
||||||
|
// VIDEO DEMO: https://www.youtube.com/watch?v=NHtRlndE2cg
|
||||||
|
|
||||||
#include <opencv2/dnn.hpp>
|
#include <opencv2/dnn.hpp>
|
||||||
#include <opencv2/dnn/shape_utils.hpp>
|
#include <opencv2/dnn/shape_utils.hpp>
|
||||||
#include <opencv2/imgproc.hpp>
|
#include <opencv2/imgproc.hpp>
|
||||||
#include <opencv2/highgui.hpp>
|
#include <opencv2/highgui.hpp>
|
||||||
using namespace cv;
|
|
||||||
using namespace cv::dnn;
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
using namespace cv::dnn;
|
||||||
|
|
||||||
const size_t network_width = 416;
|
const size_t network_width = 416;
|
||||||
const size_t network_height = 416;
|
const size_t network_height = 416;
|
||||||
|
|
||||||
const char* about = "This sample uses You only look once (YOLO)-Detector "
|
static const char* about =
|
||||||
"(https://arxiv.org/abs/1612.08242) "
|
"This sample uses You only look once (YOLO)-Detector (https://arxiv.org/abs/1612.08242) to detect objects on camera/video/image.\n"
|
||||||
"to detect objects on camera/video/image.\n"
|
"Models can be downloaded here: https://pjreddie.com/darknet/yolo/\n"
|
||||||
"Models can be downloaded here: "
|
|
||||||
"https://pjreddie.com/darknet/yolo/\n"
|
|
||||||
"Default network is 416x416.\n"
|
"Default network is 416x416.\n"
|
||||||
"Class names can be downloaded here: "
|
"Class names can be downloaded here: https://github.com/pjreddie/darknet/tree/master/data\n";
|
||||||
"https://github.com/pjreddie/darknet/tree/master/data\n";
|
|
||||||
|
|
||||||
const char* params
|
static const char* params =
|
||||||
= "{ help | false | print usage }"
|
"{ help | false | print usage }"
|
||||||
"{ cfg | | model configuration }"
|
"{ cfg | | model configuration }"
|
||||||
"{ model | | model weights }"
|
"{ model | | model weights }"
|
||||||
"{ camera_device | 0 | camera device number}"
|
"{ camera_device | 0 | camera device number}"
|
||||||
"{ video | | video or image for detection}"
|
"{ source | | video or image for detection}"
|
||||||
"{ min_confidence | 0.24 | min confidence }"
|
"{ min_confidence | 0.24 | min confidence }"
|
||||||
"{ class_names | | class names }";
|
"{ class_names | | File with class names, [PATH-TO-DARKNET]/data/coco.names }";
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
VideoCapture cap;
|
VideoCapture cap;
|
||||||
if (parser.get<String>("video").empty())
|
if (parser.get<String>("source").empty())
|
||||||
{
|
{
|
||||||
int cameraDevice = parser.get<int>("camera_device");
|
int cameraDevice = parser.get<int>("camera_device");
|
||||||
cap = VideoCapture(cameraDevice);
|
cap = VideoCapture(cameraDevice);
|
||||||
@ -73,7 +73,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cap.open(parser.get<String>("video"));
|
cap.open(parser.get<String>("source"));
|
||||||
if(!cap.isOpened())
|
if(!cap.isOpened())
|
||||||
{
|
{
|
||||||
cout << "Couldn't open image or video: " << parser.get<String>("video") << endl;
|
cout << "Couldn't open image or video: " << parser.get<String>("video") << endl;
|
||||||
@ -86,7 +86,7 @@ int main(int argc, char** argv)
|
|||||||
if (classNamesFile.is_open())
|
if (classNamesFile.is_open())
|
||||||
{
|
{
|
||||||
string className = "";
|
string className = "";
|
||||||
while (classNamesFile >> className)
|
while (std::getline(classNamesFile, className))
|
||||||
classNamesVec.push_back(className);
|
classNamesVec.push_back(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,10 +163,10 @@ int main(int argc, char** argv)
|
|||||||
String label = String(classNamesVec[objectClass]) + ": " + conf;
|
String label = String(classNamesVec[objectClass]) + ": " + conf;
|
||||||
int baseLine = 0;
|
int baseLine = 0;
|
||||||
Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
|
Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
|
||||||
rectangle(frame, Rect(Point(xLeftBottom, yLeftBottom - labelSize.height),
|
rectangle(frame, Rect(Point(xLeftBottom, yLeftBottom ),
|
||||||
Size(labelSize.width, labelSize.height + baseLine)),
|
Size(labelSize.width, labelSize.height + baseLine)),
|
||||||
Scalar(255, 255, 255), CV_FILLED);
|
Scalar(255, 255, 255), CV_FILLED);
|
||||||
putText(frame, label, Point(xLeftBottom, yLeftBottom),
|
putText(frame, label, Point(xLeftBottom, yLeftBottom+labelSize.height),
|
||||||
FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0,0,0));
|
FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0,0,0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -181,7 +181,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imshow("detections", frame);
|
imshow("YOLO: Detections", frame);
|
||||||
if (waitKey(1) >= 0) break;
|
if (waitKey(1) >= 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user