Code in the code sample I direct, and what can be compiled with cmake
After downloading the source code of OpenCV4.0, comes with sample files: opencv-4.0.0 / samples / dnn / object_detection.cpp
Referring or direct path
https://github.com/opencv/opencv/blob/master/samples/dnn/object_detection.cpp
Before running the following command after the completion of the compilation can be predicted:
./object_detection -i=dog.jpg -c=yolov3.cfg -m=yolov3.weights -classes=coco.names --scale=0.00392
Which dog.jpg file, coco.names file and yolov3.cfg files are downloaded from github in the yolov3,
https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg
https://github.com/pjreddie/darknet/blob/master/data/coco.names
https://github.com/pjreddie/darknet/blob/master/data/dog.jpg
The parameters downloaded from the following path:
https://pjreddie.com/media/files/yolov3.weights
I can find the pictures to predict, you will find the error:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.0.0) /home/luke/Download/opencv-4.0.0/modules/dnn/src/layers/concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'
We need to add the width and height parameters, note that this parameter is not your real picture width and height, but need rezise parameter reference
./object_detection -i=dog.jpg -c=yolov3.cfg -m=yolov3.weights -classes=coco.names --scale=0.00392 --width=416 --height=416
或者
./object_detection -i=dog.jpg -c=yolov3.cfg -m=yolov3.weights -classes=coco.names --scale=0.00392 --width=768 --height=576