I am currently working on a little Qt project that uses both conventional USB Webcams and two USB3 cameras. For the webcams I use OpenCV with the Direct Show API to capture images.
Getting OpenCV to work in conjunction with Qt has been really straightforward:
Set source & build directories in CMake
Configure and generate
Include OpenCV in project
However, the setup for confuses me. The Tutorial shows how to build example applications, but I can’t figure out how to include the result in my Qt project.
(How) is it possible to set up to be used in a similar way to OpenCV?
As I understand you already have a working setup for a Qt + OpenCV application?
If so the tutorial is of no use to you as it describes the Qt setup.
So in order to add CVB to your CMake project just add
file(TO_CMAKE_PATH "$ENV{CVB}/cmake" CVB_MODULE_PATH)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CVB_MODULE_PATH}")
find_package(CVB REQUIRED
COMPONENTS CvbQuick) #Component is only required if you plan to use the QML image display
and link to the CVB targets the same way you link to the Qt targets:
target_link_libraries(${PROJECT_NAME}
CVB::Cvb
CVB::CvbUI # Only required for the Cvb::UI classes
Qt5::Widgets
Qt5::Quick
)
You can check the namespace reference documentation off any CVB class for the CVB::Cvb* target you must link to. See also our examples for more variants.
Hi @Andreas,
I am sorry for my late response. In the last few days I discovered that I might have a more fundamental problem in understanding how to use CMake and CVB (I am not a professional programmer).
Yes. I built the OpenCV libraries with CMake and compiled them with mingw730_64(gcc/g++).
I tried building and compiling the QtMovie2 example but that doesn’t work. Configuration and generating the project
works without error. However, when I try to compile I get the following error:
fatal error: ../global.hpp: No such file or directory #include "../global.hpp"
manually resolving the required libs for the CVB C++ headers is quite some work.
The FindCVB.cmake files would do this work for you. QMake cannot do that.
Please note, QMake will be dropped in favour of CMake even by the Qt project with its next major release.
However, all this does not help much as, you are right about a more fundamental problem:
CVB does not support this compiler. On Widows you need a VC (>=14 for C++11) compiler.
Is there a reason why you are using C++ then? Maybe have a look at Python. Integration of and OpenCV is much easier there. There you basically need to pip install opencv-python and our python wheel, e.g. pip install "%CVB%Lib\Python\cvb-1.1-cp35.cp36.cp37-none-win_amd64.whl" (with maybe a --user option.
Edit: Qt is also supported by the way : pip install PySide2.
When I started working on my project I didn’t know I would be using CVB, only OpenCV.
If I had known that I probably woul’ve chosen Python over C++.
Yesterday I switched everything over to CMake and MSVC2017 and so far everything is working
even though Qt Creator doesn’t mesh well with CMake at all.