Opencv4.0运行yolov3
代碼我直接用的sample中的代碼,用cmake編譯一下即可
OpenCV4.0的源碼下載后,自帶的sample文件:opencv-4.0.0/samples/dnn/object_detection.cpp
或直接參看路徑
https://github.com/opencv/opencv/blob/master/samples/dnn/object_detection.cpp
編譯完成后運行如下命令即可進行前向預測:
./object_detection?-i=dog.jpg -c=yolov3.cfg -m=yolov3.weights -classes=coco.names --scale=0.00392?
其中dog.jpg文件、coco.names文件和yolov3.cfg文件均從yolov3的github中下載,
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
而參數從如下路徑下載:
https://pjreddie.com/media/files/yolov3.weights
我隨便找了張圖片進行預測,會發現報錯:
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'
需要添加上寬高的參數,注意這個參數不是你圖片的真實寬高,而是需要rezise的參數,參考
./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
?
?
總結
以上是生活随笔為你收集整理的Opencv4.0运行yolov3的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu安装TensorFlow-g
- 下一篇: tf.squeeze示例代码