0

I'm trying to use opencv in a QT project for a raspberry pi 4. I'm on a Linux machine

Here is my .pro file and errors I get. And my mainwindow.cpp

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

TRANSLATIONS += \
    SCWWS_fr_FR.ts

CONFIG += lrelease
CONFIG += embed_translations

# Default rules for deployment.
qnx: target.pHere is my mainwindow.cppath = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    resources.qrc


unix:!macx: LIBS += -L$$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_shape -lopencv_videoio

INCLUDEPATH += $$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/include
DEPENDPATH += $$PWD/../../Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/include

Here is my mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtCore>
#include <QFontDatabase>
#include <QDebug>
#include <QImage>

//#include "opencv2/core.hpp"
//#include "opencv2/highgui.hpp"

//using namespace cv;

mainwindow::mainwindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::mainwindow)
{
    QFontDatabase::addApplicationFont(":/fonts/roboto-light.ttf");
    ui->setupUi(this);

    qDebug() << "Hello  World !";

    //cv::VideoCapture camera = VideoCapture(0);
    //
    //Mat frame;
    //camera >> frame;
    //QImage img(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888);
    //ui->label->setPixmap(QPixmap::fromImage(img));
}

mainwindow::~mainwindow()
{
    delete ui;
}

And here are errors I get

libXinerama.so.1, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libgdk-3.so.0, not found (try using -rpath or -rpath-link)

libmmal_core.so, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libavcodec.so.58, not found (try using -rpath or -rpath-link)

libmmal_vc_client.so, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libavcodec.so.58, not found (try using -rpath or -rpath-link)
.
.
.
liblapack.so.3, needed by /home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/lib/libarmadillo.so.9, not found (try using -rpath or -rpath-link)

/home/lolix/Documents/Qt-CrossCompile-RaspberryPi/raspberrypi4/sysroot/usr/lib/arm-linux-gnueabihf/libopenmpt.so.0:-1: error: undefined reference to `std::random_device::_M_getentropy() const@GLIBCXX_3.4.25'

Errors arrives has soon has I uncomment my code. The version of open cv on the RP4 is 3.2 and when I install it on my machine it's 4.5. Event if I use the same command sudo apt-get install libopencv-dev Thanks for your help

**EDIT**

I was able to get rid of these errors with this response. But a new one appeared undefined reference to std::random_device::_M_getentropy() const@GLIBCXX_3.4.25

Lolix Dudu
  • 313
  • 2
  • 15
  • 1
    Please use code blocks. It is my understanding that photos of code is unacceptable here on SO (which could be why you got downvoted). – developer01 Nov 02 '21 at 21:34

1 Answers1

0

Regarding OpenCV I suggest to build it from source, for the RPi I always cross-compile using docker, as described here (just remove the references to openvino). At this point you also need to cross-compile Qt for the RPi, but I guess you already did it.

rok
  • 2,574
  • 3
  • 23
  • 44
  • I followed this [tutorial](https://gist.github.com/willprice/abe456f5f74aa95d7e0bb81d5a710b60) to install opencv on my RP4. I succesfully cross compiled a qt app with qt creator. The problem appear when I try to include opencv to my project. I don't know what todo next, should I `rsync` again ? – Lolix Dudu Nov 03 '21 at 12:01
  • Well now there is a new error, ```undefined reference to std::random_device::_M_getentropy() const@GLIBCXX_3.4.25'``` – Lolix Dudu Nov 03 '21 at 12:07
  • try to look at [this](https://stackoverflow.com/a/61421195/4267439) – rok Nov 03 '21 at 13:39
  • if I understand correctly, I must use the same compiler as the one used to compile qt ? – Lolix Dudu Nov 03 '21 at 13:49
  • if you cross compile an application in you host linux which uses Qt and OpenCV the idea is to have also OpenCV cross-compiled in your host.. Probably you are using a gcc version to crosscompile that is too old wtr to the one used to compile opencv (in the Rpi).. Cross-Compile everything on the host, or try to use at least the same GCC version. – rok Nov 03 '21 at 14:17
  • So I tried to compile OpenCv with Cmake Gui , and when I execute `make` in my build folder, I get this error `fatal error: zlib.h: No such file or directory` – Lolix Dudu Nov 03 '21 at 14:33
  • Ok this one is solve quite easly with [this](https://stackoverflow.com/a/58679524/13529134) help – Lolix Dudu Nov 03 '21 at 14:41
  • So I compiled OpenCv with the same compiler has I compiled Qt, I do `make install` on my linux machine. What can I do on my RP4 ? – Lolix Dudu Nov 03 '21 at 15:09
  • 1
    You have to cross-compile OpenCV for RPi on your linux machine, then you cross-compile your application linking your executable with this opencv libs you just cross-compiled.. if everythig is fine you can move executable and cross-compiled libs on the RPi.. – rok Nov 04 '21 at 11:52
  • Works nice but I need to launch the program manually on the raspberry pi. Now I got this error in Qt Creator : `error while loading shared libraries: libopencv_core.so.4.5: cannot open shared object file: No such file or directory` – Lolix Dudu Nov 04 '21 at 15:25
  • tha's another issue.. probably at runtime libraries are not found because they are not in a system path, there are multiple ways to do this.. export LD_LIBRARY_PATH, create a conf file in /etc/ld.so.conf.d .. etc.. – rok Nov 06 '21 at 10:00