how to deploy openvino-opencv in Qt

流过昼夜 提交于 2021-01-01 09:29:02

问题


I want to use openvino-opencv for my Qt (Qt5.7.1) based project. I have downloaded and installed openvino411 (corresponding to opencv411) following the instructions here in windows10 https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_windows.html#Configure_MO. I write a .pri file to demploy the opencv in Qt:

INCLUDEPATH += C:/openvino-411/openvino_2019.2.275/opencv/include

CONFIG(release, debug|release):{
    LIBS += -LC:/openvino-411/openvino_2019.2.275/opencv/lib \
            -lopencv_core411 -lopencv_highgui411 -lopencv_imgproc411 -lopencv_imgcodecs411 -lopencv_features2d411 -lopencv_ml411 -lopencv_objdetect411 -lopencv_dnn411
}
CONFIG(debug, debug|release):{
    LIBS += -LC:/openvino-411/openvino_2019.2.275/opencv/lib \
            -lopencv_core411d -lopencv_highgui411d -lopencv_imgproc411d -lopencv_imgcodecs411d -lopencv_features2d411d -lopencv_ml411d -lopencv_objdetect411d -lopencv_dnn411d
}

But it seeems opencv canot be run in Qt, since I tried running the qt program. The popping up cmd window goes directly to "Press <RETURN> to close this window..." without doing any actually.


回答1:


First of all, keep in mind that OpenVINO for windows is compiled against MSBUILD instead of MinGW, so if your Qt project is compiled using MinGW, OpenVINO pre-built libraries will likely fail during linking

That said, I managed to integrate OpenVINO Inference Engine with OpenCV succesfully in a big and already existent Qt based project (QT 5.13.1), under LINUX (Ubuntu 16.04), it apperas that under Windows the dependencies fragmentation makes it harder

This configuration is quite tricky and also is a work in progress (to me), I am trying to completely isolate OpenVINO dependencies aiming to deploy them completely embedded in our app, anyway like this it works:

First I installed OpenVINO (https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html) paying particular attention in following each step precisely as it is described,

also DON'T MISS TO RUN the two examples demo_security_barrier_camera and demo_squeezenet_download_convert_run, they will produce two libraries libcpu_extension.so and libgflags_nothreads.a WITHOUT WHICH OpenVINO WILL NOT WORK UNDER YOUR PROJECT, the reason why it was made this way is unknown to me

I copied the following libraries under a subfolder of my project (ThirdPartyLibraries/OpenVINOInferenceEngine):

  • libinference_engine.so (found in OpenVINO installation folder: /opt/intel/openvino/inference_engine/lib/intel64/libinference_engine.so)
  • libtbb.so (found in OpenVINO installation folder: /opt/intel/openvino/inference_engine/external/tbb/lib/intel64/libtbb.so)

for the two "cpu extension" libraries, I created a subfolder named "extension", so:

  • extension/libgflags_nothreads.a (found in OpenVINO Inference Engine Demo BUILD FOLDER, for me it is /home/myuser/inference_engine_demos_build/Release/lib/libgflags_nothreads.a)
  • extension/libcpu_extensio.so (found in OpenVINO Inference Engine Demo BUILD FOLDER, for me it is /home/myuser/inference_engine_demos_build/Release/lib/libcpu_extensio.so)

Then I also copied the includes of Inference Engine and Lib Cpu Extension from their respective installation folders to my ThirdPartyLibraries:

  • All the content found under /opt/intel/openvino/inference_engine/include/ goes under /ThirdPartyLibraries/OpenVINOInferenceEngine/include
  • All the content found under /opt/intel/openvino/deployment_toos/inference_engine/src/extension/ goes under /ThirdPartyLibraries/OpenVINOInferenceEngine/extension/include

Finally here's my .pri file for Qt:

OPENVINODIR = /home/myuser/code_qt5_HG/Libraries/ThirdPartyLibraries/OpenVINOInferenceEngine

LIBS_OPENVINO  += -L$$OPENVINODIR \
                  -linference_engine \
                  -ltbb \
                  -L$$OPENVINODIR/extension \
                  -lcpu_extension

INCLUDES_OPENVINO  += $$OPENVINODIR/include \
                   += $$OPENVINODIR/extension/include

LIBS += $$LIBS_OPENVINO

INCLUDEEPATH += $$INCLUDES_OPENVINO

That's it, doing so allows me to reference and use Inference Engine in my project like this:

 #include <ie_core.hpp>
 #include <ie_plugin_config.hpp>
 #include <cpp/ie_cnn_net_reader.h>
 #include <ext_list.hpp>

 .....

 InferenceEngine::Core ie;
 ie.AddExtension(std::make_shared<InferenceEngine::Extensions::Cpu::CpuExtensions>(), "CPU");
 InferenceEngine::CNNNetReader netReader;
 netReader.ReadNetwork(detectorXmlPath);
 netReader.getNetwork().setBatchSize(1);
 netReader.ReadWeights(detectorBinPath);
 InferenceEngine::InputsDataMap inputInfo(netReader.getNetwork().getInputsInfo());

 .....

to deploy my App to a third party machine I need to install OpenVINO on the machine following the regular procedure (https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html) and to deploy my App as I usually do, the dependencies are then correctly resolved.

My last two cents: I am in direct contact with Intel, which is supporting me with the OpenVINO integration, according to them "all the .so files in in /deployment_tools/inference_engine/lib/intel64, from /deployment_tools/inference_engine/external/mkltiny_lnx/lib, and /deployment_tools/inference_engine/external/tbb/lib are pretty much all the dependencies required", I still didn't have the time to confirm that yet



来源:https://stackoverflow.com/questions/57727665/how-to-deploy-openvino-opencv-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!