Building CVB with CMake for use in Qt

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:

  1. Set source & build directories in CMake

  2. Configure and generate

  3. Include OpenCV in project

However, the setup for :cvb: 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 :cvb: to be used in a similar way to OpenCV?

Hi @Whirlwind,

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"

Now to my “fundamental” question:

To use OpenCV in QT I have to do the following:

*.pro
INCLUDEPATH += D:\OpenCV\opencv_411_x64\install\include
LIBS += D:\OpenCV\opencv_411_x64\install\x64\mingw\bin\libopencv__core411.dll

main.cpp
#include <opencv2/core.hpp>

CMake only was needed to build OpenCV.
I assume that CVB works in a similar fashion?

*.pro
INCLUDEPATH += D:\CVB\Lib\C
LIBS += D:\CVB\*Path to compiled library*

main.cpp	
#include <cvb/driver/driver.hpp>

Because right now I am not sure how to get to the “compiled library” part.

Hi @Whirlwind,

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.

Thanks for the quick response. That clears things up for me.

Is there a reason why you are using C++ then? Maybe have a look at Python. Integration of :cvb: 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 :wink:: pip install PySide2.

See here for more information:

Hi @parsd,
I’m using C++ for two reasons:

  1. I am most familiar with it.

  2. 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 :slight_smile:
even though Qt Creator doesn’t mesh well with CMake at all.

1 Like