Qt and OpenCV help
-
Hi I am looking to build a gui with qt and OpenCV and wondering which way would be best to combine them. Should I install both in a VM and cross compile or install both on the Pi. I have a Pi4 B+ and have OpenCV 4.3.0 built from source working on it. I had qt creator built on a VM Ubuntu machine cross compiled to the Pi but I could not get OpenCV to work with it. I had to resize my VM hd but it would not boot after so I’m starting again and looking for pointers. Is there any guides for this. When I had qt working included the header files in the . Pro but they didn’t appear in the main and got errors no such files when tried to build with the OpenCV commands. Thanks for any help.
-
@robd said in Qt and OpenCV help:
I could not get OpenCV to work with it
What was the problem?
And to make it clear: you need to cross-compile Qt for RPi, not QtCreator. -
Hello,
the solution that I adopted is https://doc.qt.io/QtForDeviceCreation/qtee-custom-embedded-linux-image.html, where you build a custom image and the cross compiler. In this way you can customize your image and toolchain without downloading any source code because it's the program itself that takes care of it.
For adding the opencv I simply add in local.conf file IMAGE_INSTALL += "opencv". -
How much time have you spent on try to cross compile?
I have OpenCV working with Qt in Mac, Linux (amd64 and Raspberry Pi) and Windows.
After have compile the project I can test it in each real machine.
Raspberry Pi is not so slow to compile and if you want you can mount a remote file system so you can have the armhf binaries in a folder of you pc.
Have a look at a .pro file of a multiplatform project that uses OpenCV and FFMpeg.#------------------------------------------------- # # Project created by QtCreator 2012-12-28T15:17:02 # #------------------------------------------------- QT += core gui xml network serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ComputerVisionStudio TEMPLATE = app unix:!mac { LIBS += -Wl,-rpath=\\\$$ORIGIN/libs } unix { INCLUDEPATH += ../../opencv-3.3.1/build INCLUDEPATH += ../../opencv-3.3.1/include INCLUDEPATH += ../../opencv-3.3.1/modules/calib3d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/opencv_contrib-master/modules/face/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/core/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/features2d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/flann/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/hal/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/highgui/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/imgcodecs/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/imgproc/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/ml/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/objdetect/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/opencv_contrib-master/modules/xfeatures2d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/photo/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/shape/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/stitching/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/superres/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/video/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/videoio/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/videostab/include/ } windows { INCLUDEPATH += ../../opencv-3.3.1/build INCLUDEPATH += ../../opencv-3.3.1/include INCLUDEPATH += ../../opencv-3.3.1/modules/calib3d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/opencv_contrib-master/modules/face/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/core/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/features2d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/flann/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/hal/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/highgui/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/imgcodecs/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/imgproc/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/ml/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/objdetect/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/opencv_contrib-master/modules/xfeatures2d/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/photo/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/shape/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/stitching/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/superres/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/video/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/videoio/include/ INCLUDEPATH += ../../opencv-3.3.1/modules/videostab/include/ } unix { INCLUDEPATH += ../../openalpr-master/src/openalpr/ } windows { INCLUDEPATH += ../../openalpr_32/include } unix { INCLUDEPATH += ../../ffmpeg-4.2.2/ unix:!mac { #LIBS += ../../opencv-3.3.1/build/lib/libopencv_adas.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_bgsegm.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_bioinspired.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_calib3d.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_ccalib.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_core.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_datasets.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_face.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_features2d.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_flann.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_highgui.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_imgcodecs.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_imgproc.so #LIBS += ../../opencv-3.3.1/build/lib/libopencv_latentsvm.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_line_descriptor.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_ml.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_objdetect.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_optflow.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_photo.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_reg.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_rgbd.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_saliency.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_shape.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_stereo.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_stitching.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_superres.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_surface_matching.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_text.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_tracking.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_video.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_videoio.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_videostab.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_xfeatures2d.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_ximgproc.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_xobjdetect.so LIBS += ../../opencv-3.3.1/build/lib/libopencv_xphoto.so LIBS += ../../ffmpeg-4.2.2/libavcodec/libavcodec.so LIBS += ../../ffmpeg-4.2.2/libavdevice/libavdevice.so LIBS += ../../ffmpeg-4.2.2/libswresample/libswresample.so LIBS += ../../ffmpeg-4.2.2/libavfilter/libavfilter.so LIBS += ../../ffmpeg-4.2.2/libavformat/libavformat.so LIBS += ../../ffmpeg-4.2.2/libavutil/libavutil.so LIBS += ../../ffmpeg-4.2.2/libpostproc/libpostproc.so LIBS += ../../ffmpeg-4.2.2/libswscale/libswscale.so #LIBS += ../../x264-snapshot-20161201-2245/libx264.so.148 LIBS += ../../openalpr-master/src/build/openalpr/libopenalpr.so LIBS += ../../QtFFmpegPlayer/QtFFmpegPlayer-build-desktop/qthffmpegplayer.o LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/qchttpclient.o LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/httpcommons.o } unix:mac { #LIBS += -framework AVFoundation #LIBS += -framework CoreFoundation #LIBS += -framework CoreVideo #LIBS += -framework Foundation #LIBS += -framework IOKit #LIBS += ../../opencv-3.3.1/build/lib/libopencv_adas.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_bgsegm.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_bioinspired.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_calib3d.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_ccalib.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_core.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_datasets.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_face.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_features2d.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_flann.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_highgui.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_imgcodecs.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_imgproc.3.3.1.dylib #LIBS += ../../opencv-3.3.1/build/lib/libopencv_latentsvm.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_line_descriptor.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_ml.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_objdetect.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_optflow.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_photo.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_reg.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_rgbd.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_saliency.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_shape.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_stereo.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_stitching.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_superres.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_surface_matching.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_text.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_tracking.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_video.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_videoio.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_videostab.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_xfeatures2d.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_ximgproc.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_xobjdetect.3.3.1.dylib LIBS += ../../opencv-3.3.1/build/lib/libopencv_xphoto.3.3.1.dylib LIBS += ../../ffmpeg-4.2.2/libavcodec/libavcodec.dylib LIBS += ../../ffmpeg-4.2.2/libavdevice/libavdevice.dylib LIBS += ../../ffmpeg-4.2.2/libswresample/libswresample.dylib LIBS += ../../ffmpeg-4.2.2/libavfilter/libavfilter.dylib LIBS += ../../ffmpeg-4.2.2/libavformat/libavformat.dylib LIBS += ../../ffmpeg-4.2.2/libavutil/libavutil.dylib LIBS += ../../ffmpeg-4.2.2/libpostproc/libpostproc.dylib LIBS += ../../ffmpeg-4.2.2/libswscale/libswscale.dylib LIBS += ../../openalpr-master/src/build/openalpr/libopenalpr.dylib LIBS += ../../QtFFmpegPlayer/QtFFmpegPlayer-build-desktop/qthffmpegplayer.o LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/qchttpclient.o LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/httpcommons.o } } windows { LIBS += ../../opencv-3.3.1/build/3rdparty/lib/Release/libjpeg.lib LIBS += ../../opencv-3.3.1/build/3rdparty/lib/Release/libpng.lib LIBS += ../../opencv-3.3.1/build/3rdparty/lib/Release/libtiff.lib LIBS += ../../opencv-3.3.1/build/3rdparty/lib/Release/libwebp.lib LIBS += ../../opencv-3.3.1/build/3rdparty/lib/Release/zlib.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_core331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_core331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_face331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_features2d331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_highgui331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_imgcodecs331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_imgproc331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_objdetect331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_photo331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_video331.lib LIBS += ../../opencv-3.3.1/build/lib/Release/opencv_videoio331.lib INCLUDEPATH += ../../ffmpeg-4.2.2/include LIBS += ../../ffmpeg-4.2.2/lib/avcodec.lib LIBS += ../../ffmpeg-4.2.2/lib/avdevice.lib LIBS += ../../ffmpeg-4.2.2/lib/swresample.lib LIBS += ../../ffmpeg-4.2.2/lib/avfilter.lib LIBS += ../../ffmpeg-4.2.2/lib/avformat.lib LIBS += ../../ffmpeg-4.2.2/lib/avutil.lib LIBS += ../../ffmpeg-4.2.2/lib/postproc.lib LIBS += ../../ffmpeg-4.2.2/lib/swscale.lib LIBS += ../../openalpr_32/openalpr.lib LIBS += ../../QtFFmpegPlayer/QtFFmpegPlayer-build-desktop/release/qthffmpegplayer.obj LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/release/qchttpclient.obj LIBS += ../../QtHTTPClient/QtHTTPClient-build-desktop/release/httpcommons.obj } # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ exif.cpp \ main.cpp \ ... HEADERS += \ exif.h \ ... FORMS += \ qfmainwindow.ui \ ... RESOURCES += \ Resourcefile.qrc TRANSLATIONS = ComputerVisionStudio_it.ts RC_FILE = ComputerVisionStudio.rc ICON = ComputerVisionStudio.icns DISTFILES += \ ComputerVisionStudio_it.ts