Error first OPENCV project on Raspberry Pi 2



  • Hello.

    I'm trying to run Opencv on raspberry and i can't... In Windows, I work with Qt and OpenCv without problems, but in Raspberry appears an error with all funtions:

    My code is:

    temporal.pro:

       QT       += core gui
    
       greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
       TARGET = temporal
       TEMPLATE = app
    
        SOURCES += main.cpp\
        mainwindow.cpp
    
        HEADERS  += mainwindow.h
    
        FORMS    += mainwindow.ui
    
        INCLUDEPATH +=/usr/local/include
        LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
    

    mainwindow.h:

        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        #include <opencv2/core/core.hpp>
        #include <opencv2/highgui/highgui.hpp>
        #include <opencv2/imgproc/imgproc.hpp>
        #include <QMainWindow>
        #include <iostream>
        #include <stdio.h>
        #include <stdlib.h>
    
        namespace Ui {
        class MainWindow;
        }
    
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
    
        public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();
    
        private slots:
            void on_pushButton_clicked();
    
        private:
            Ui::MainWindow *ui;
        };
    
        #endif // MAINWINDOW_H
    

    main.cpp:

        #include "mainwindow.h"
        #include <QApplication>
    
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            MainWindow w;
            w.show();
        }
    

    mainwindow.cpp:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
    
        #include <opencv2/highgui/highgui.hpp>
    
        using namespace cv;
    
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        }
    
        MainWindow::~MainWindow()
        {
            delete ui;
        }
    
        void MainWindow::on_pushButton_clicked()
        {
            Mat img = imread("/home/pi/test.png",1);
        }
    

    I make test and the problem appears when i write the function, in this case, imread. And the error is:

    mainwindow.o: undefined reference to symbol '_ZN2cv6String10deallocateEv'
    error adding symbols: DSO missing from command line
    collect2: error: Id returned 1 exit status

    Any idea??

    Many thanks!!!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you building directly on the Pi2 ?



  • @SGaist Yes, I make this project on Qt in Raspberry. I installed opencv following this video: https://youtu.be/rEaQqZ7VM70


  • Lifetime Qt Champion

    Looks like for some reason there's a symbol from opencv_core that is not found. Can you try to build a basic main.cpp only using OpenCV ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.