Qt5 Openvino opencv cmake windows

457 views Asked by At

I am trying to develop an application with qt that uses the openvino inference engine with opencv.
I have been trying to create the project with qmake first but I couldn't manage then I switched to cmake an which led to some improvements but still no success.
openvino: openvino_2020.04.287
opencv: the one included in openvino
cmake: 3.14.7
qt: qt 5_15_0\

As I have read openvino works with mscvc so that is what i am using instead of mingw.
My CMakeLists.txt looks as follows:

cmake_minimum_required(VERSION 3.14.7 FATAL_ERROR)

project(PortraitSegmentationWin LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(QT5 REQUIRED COMPONENTS Core Widgets Gui)
find_package(InferenceEngine REQUIRED)
find_package(OpenCV REQUIRED)


set(project_ui
    mainwindow.ui)

set(project_headers
    mainwindow.h)

set(project_sources
    main.cpp
    mainwindow.cpp)

qt5_wrap_ui(project_headers_wrapped ${project_ui})
qt5_wrap_cpp(project_sources_moc ${project_headers})

add_executable(${PROJECT_NAME} ${project_headers} 
               ${project_sources} ${project_headers_wrapped} 
               ${project_sources_moc})

target_link_libraries(${PROJECT_NAME}
    PUBLIC
    ${QT5Widgets_LIBRARIES}
    ${Qt5Core_LIBRARIES}
    ${QT5Gui_LIBRARIES}
    ${InferenceEngine_LIBRARIES} 
    ${OpenCV_LIBS} )


And when it gives me the following error:
CMake Error at PortraitSegmentationWin/CMakeLists.txt:22 (qt5_wrap_ui): Unknown CMake command "qt5_wrap_ui".\

This I managed to solve if I use find_package(Qt5Widgets) and then I can proceed to the Generate option and the I can even open the project but then when I build it, it fails and gives me LINK2019 and LINK2001 error 144 one of them...

Another version of my CMakeLists.txt is:

cmake_minimum_required(VERSION "3.14.7")

project(PortraitSegmentation_openVINO_OpenCV LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(InferenceEngine REQUIRED)
find_package(ngraph REQUIRED)
find_package(OpenCV REQUIRED)

set(PortraitSegmentation_openVINO_OpenCV
    main.cpp
    mainwindow.cpp
    mainwindow.h
    mainwindow.ui
    )

add_executable(PortraitSegmentation_openVINO_OpenCV
  main.cpp
  mainwindow.cpp
  mainwindow.h
  mainwindow.ui
  )


target_link_libraries(PortraitSegmentation_openVINO_OpenCV PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt5::Core Qt5::Gui  ${InferenceEngine_LIBRARIES} ${OpenCV_LIBRARIES} ${NGRAPH_LIBRARIES})

This on the other hand tells me that there is no qt-plugin detected.
I am really clueless here I would appreciate some help of any sort!

Thanks in advance

2

There are 2 answers

1
Rommel_Intel On

First and foremost, you should read these to get more infos on what's works:

  1. how to deploy openvino-opencv in Qt

  2. https://community.intel.com/t5/Intel-Distribution-of-OpenVINO/SOLVED-Develop-OpenVINO-with-QT/td-p/1147234

Next, the biggest concern is, which OS you are running the QT in. If you are using Windows, you need to have all the prerequisite as in here: https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_windows.html

Same thing applies for others (Note: you can search for other OS on left corner & ensure the correct version on top right dropdown menu )

Ensure to run the setupvars each time you open a new terminal.

0
Rommel_Intel On

if you set the setupvars permanently as in Linux, then you don't have to initiate it each time you open a new terminal. However, most of the time in Windows, you required to do so as in the guide I provided above does not specify on doing permanently initiation of setupvars.

The error No symbol loaded for inference_engined.dll must related with LINK2019 and LINK2001 error which might caused by MSbuild. I recommend for you to uninstall all version of Microsoft Visual Studio with its MSBuild and try to reinstall the version 2019 with MSBuild. This solved my problem previously.