• YOLO---YOLOv3 with OpenCV 再使用


                                                                    YOLO---YOLOv3 with OpenCV 再使用
    YOLOv3 with OpenCV官网 @ https://github.com/JackKoLing/opencv_deeplearning_practice/tree/master/pracice3_opencv_yolov3
      下载并备齐:yolov3.weights权重文件、yolov3.cfg网络构建文件、coco.names、xxx.jpg、xxx.mp4文件、object_detection_yolo.cpp、object_detection_yolo.py等文件;
      依赖环境:C++的编译环境(如G++/VScode)、OpenCV3.4.2+(记住安装目录)
      编译情况:下载源文件,无需复杂的编译,直接修改进行应用
      支持:windows + linux  + CPU + GPU(可适用于英特尔)

    特点:
    (1)在OpenCV中使用YOLOv3, 可以在windows下+ ubuntu下使用。
    (2)windows下,之前做,object_detection_yolo.cpp是在Visual Studio(VS)下编译的。
    (3)ubuntu下,这次,object_detection_yolo.cpp是g++编译的。
    (3)OpenCV的DNN,GPU仅使用英特尔的GPU进行测试,因此如果没有英特尔GPU,代码会将您切换回CPU。
    使用:
    (1)object_detection_yolo.cpp,执行:
    编译,g++ `pkg-config opencv --cflags` object_detection_yolo.cpp -o object_detection_yolo `pkg-config opencv --libs` -std=c++11
    测试,a single image:
        ./object_detection_yolo --image=./data/1.jpg
         a video file:
        ./object_detection_yolo --video=./data/run.mp4

    (2)object_detection_yolo.py,执行:
    a single image:
        python3 object_detection_yolo.py --image=bird.jpg
    a video file:
        python3 object_detection_yolo.py --video=run.mp4

    #readme.txt
    Run the getModels.sh file from command line to download the needed model files sudo chmod a+x getModels.sh ./getModels.sh Python: Commandline usage to colorize a single image: python3 object_detection_yolo.py --image=bird.jpg a video file: python3 object_detection_yolo.py --video=run.mp4 C++: a single image: ./object_detection_yolo.out --image=bird.jpg a video file: ./object_detection_yolo.out --video=run.mp4 Compilation examples: g++ -ggdb `pkg-config --cflags --libs /usr/local/Cellar/opencv3/3.4.2/lib/pkgconfig/opencv.pc` object_detection_yolo.cpp -o object_detection_yolo.out g++ -ggdb `pkg-config --cflags --libs /usr/local/opencv3.4.2/lib/pkgconfig/opencv.pc` object_detection_yolo.cpp -o object_detection_yolo.out # For OpenCV 2.4.x cd /path/to/opencv/samples/c/ # For OpenCV 3 cd /path/to/opencv/samples/cpp/ #Compile g++ -ggdb facedetect.cpp -o facedetect `pkg-config --cflags --libs opencv` #run ./facedetect /usr/local/opencv3.4.2/include/opencv2/?? cd /home/u/opencv3.4.2/samples/cpp/ ?? g++ -ggdb `pkg-config --cflags --libs /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc` object_detection_yolo.cpp -o object_detection_yolo.out g++ -ggdb object_detection_yolo.cpp -o object_detection_yolo.out `pkg-config --cflags --libs /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc` g++ object_detection_yolo.cpp -o object_detection_yolo `pkg-config --cflags --libs /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc`


    -------------------具体遇见问题与解决----------------------
    (1)只要环境搭建好,object_detection_yolo.py运行比较顺畅,没有出现什么问题
    (2)object_detection_yolo.cpp编译时,遇见问题

    运行:
    g++ object_detection_yolo.cpp -o object_detection_yolo `pkg-config --cflags --libs /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc`
    
    报错:
    No package 'object_detection_yolo' found
    object_detection_yolo.cpp:10:31: fatal error: opencv2/highgui.hpp: 没有那个文件或目录
     #include <opencv2/highgui.hpp>
                                   ^
    compilation terminated.
    u@u1604:~/yolov3-opencv3.4.2/yolo-opencv$ g++ `pkg-config object_detection_yolo --cflags` object_detection_yolo.cpp  -o opencv `pkg-config opencv --libs`
    Package object_detection_yolo was not found in the pkg-config search path.
    Perhaps you should add the directory containing `object_detection_yolo.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'object_detection_yolo' found
    object_detection_yolo.cpp:11:31: fatal error: opencv2/imgproc.hpp: 没有那个文件或目录
     #include <opencv2/imgproc.hpp>
                                   ^
    compilation terminated.
    u@u1604:~/yolov3-opencv3.4.2/yolo-opencv$ g++ `pkg-config object_detection_yolo --cflags` object_detection_yolo.cpp  -o opencv `pkg-config opencv --libs`
    Package object_detection_yolo was not found in the pkg-config search path.
    Perhaps you should add the directory containing `object_detection_yolo.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'object_detection_yolo' found
    object_detection_yolo.cpp:13:27: fatal error: opencv2/dnn.hpp: 没有那个文件或目录
     #include <opencv2/dnn.hpp>
                               ^
    compilation terminated.

    解决:
    查看object_detection_yolo.cpp中highgui.hppimgproc.hpp、dnn.hpp都能找到文件,猜测是路径读不进来,按提示更改,
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/dnn/dnn.hpp>
    //#include <opencv2/highgui.hpp>
    //#include <opencv2/imgproc.hpp>
    //#include <opencv2/dnn.hpp>
    --------------------
    拷贝
    sudo cp -r /home/用户名/桌面/lib /usr
    sudo cp -r /home/u/桌面/dnn.hpp /usr/include/opencv2/dnn
    新建
    sudo touch filename 新建文件
    sudo mkdir foldername 新建文件夹
    删除
    sudo rm -rf 文件夹
    sudo rm -rf 文件
    ----------------------------------
    上一步,通了
    继续执行: g++ `pkg-config opencv --cflags` object_detection_yolo.cpp -o object_detection_yolo `pkg-config opencv --libs`
    参考 g++ `pkg-config opencv --cflags` opencv.cpp -o opencv `pkg-config opencv --libs` #将OpenCV的库包含进去,进行编译
    报错:
    ------------------------------ u@u1604:~/yolov3-opencv3.4.2/yolo-opencv$ g++ `pkg-config opencv --cflags` object_detection_yolo.cpp -o object_detection_yolo `pkg-config opencv --libs` object_detection_yolo.cpp: In function ‘int main(int, char**)’: object_detection_yolo.cpp:77:31: error: no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)’ ifstream ifile(str); ------------------------------
    解决:
    gcc
    /g++以c++11编译(仅g++ 4.8及以上版本才支持C++ 11标准。)
    g++ --version
    g++ -V
    再执行OK: g
    ++ `pkg-config opencv --cflags` object_detection_yolo.cpp -o object_detection_yolo `pkg-config opencv --libs` -std=c++11

    执行可执行文件:
    ./object_detection_yolo --image=./data/1.jpg

    *****************************#20191011再用**************************************

    #20191011
    
    g++ `pkg-config opencv --cflags` yolo.cpp -o yolo `pkg-config opencv --libs` -std=c++11
    
    a single image:
        ./yolo --image=./data/1.jpg
    a video file:
        ./yolo --video=./data/run.mp4
    
    使用语法:
    u@u160406:~/yolo-opencv$ g++ `pkg-config opencv --cflags` yolo.cpp -o yolo `pkg-config opencv --libs` -std=c++11
    u@u160406:~/yolo-opencv$ ./yolo --video=./data/run.mp4

  • 相关阅读:
    Service Broker between two instance
    第一次调用Web service响应速度慢的解决办法
    MVC静态化
    WinFrom Exception Handler
    The difference for ROW_NUMBER/RANK/DENSE_RANK/NTILE
    字符编码
    TSQL中的参数与变量
    Entity Framework Power Tool
    Use ActionFilterAttribute to check user logging
    SiteFactory技术实现QQ群19452522用户交流贴
  • 原文地址:https://www.cnblogs.com/carle-09/p/11326544.html
Copyright © 2020-2023  润新知