generate an exe on QT5.2 and OpenCV 3.1 in static mod.



  • Hello,
    I am a beginner in QT, and I want to generate a static application using OpenCV.
    I have already generated QT 5.2 in static modes, and opencv 3.1 also static mode using Mingw32.
    I can generate a qt.exe application, by using opencv and even exported to other PC.
    Once I added imread, i can't compile the code.
    Here are my files ..

    files.pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = sans_titre4
    TEMPLATE = app
    
    message("* Using settings for Windows moez.")
    INCLUDEPATH += "C:\\OOpenCV\\buildQT6\\install\\include" \
                    "C:\\OOpenCV\\buildQT6\\install\\include\\opencv" \
                    "C:\\OOpenCV\\buildQT6\\install\\include\\opencv2"
    
    
    LIBS += -LC:\\OOpenCV\\buildQT6\\install\\x86\\mingw\\staticlib\
    -lIlmImf \
    -llibjasper \
    -llibjpeg \
    -llibpng \
    -llibtiff \
    -llibwebp \
    -lzlib \
    -lopencv_calib3d310 \
    -lopencv_core310 \
    -lopencv_features2d310 \
    -lopencv_flann310\
    -lopencv_highgui310 \
    -lopencv_imgcodecs310 \
    -lopencv_imgproc310 \
    -lopencv_ml310 \
    -lopencv_objdetect310 \
    -lopencv_photo310 \
    -lopencv_shape310 \
    -lopencv_stitching310 \
    -lopencv_superres310 \
    -lopencv_ts310 \
    -lopencv_video310 \
    -lopencv_videoio310 \
    -lopencv_videostab310 \
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    

    main.cpp

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

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    
    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;
         cv::Mat m_zero ;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QDebug>
    #include <QFileDialog>
    #include <QMessageBox>
    
    #include <cv.h>
    
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        m_zero = cv::Mat::zeros(10, 20, CV_32F);
    
        // Display dialog so the user can select a file
        QString filename = QFileDialog::getOpenFileName(this,
                                                        tr("Open Image"),
                                                        QDir::currentPath(),
                                                        tr("Files (*.png *.jpg *.tiff *.bmp)"));
    
        if (filename.isEmpty()) // Do nothing if filename is empty
            return;
    
    
        int Height = m_zero.size().height;
        QString::number(Height);
    
        qDebug() << Height ;
        QString Height_Qstring = QString::number(Height);
    
        m_zero = cv::imread("CSC_0113.JPG", CV_LOAD_IMAGE_COLOR);
        m_zero = cv::imread(filename.toStdString(), CV_LOAD_IMAGE_COLOR);
    
        QMessageBox msgBox;
        msgBox.setText(Height_Qstring + "   " + filename);
        msgBox.exec();
    
    
    }
    

    this the errors

    grfmt_webp.cpp:-1: erreur&nbsp;: undefined reference to `WebPGetFeaturesInternal'
    grfmt_webp.cpp:-1: erreur&nbsp;: undefined reference to `WebPDecodeBGRInto'
    :-1: erreur&nbsp;: C:\OOpenCV\buildQT6\install\x86\mingw\staticlib\libopencv_imgcodecs310.a(grfmt_webp.cpp.obj): bad reloc address 0x130 in section `.text$_ZN2cv11WebPDecoder8readDataERNS_3MatE'
    :-1: erreur&nbsp;: final link failed: Invalid operation
    collect2.exe:-1: erreur&nbsp;: error: ld returned 1 exit status
    
    

    if i comment this 2 lignes

     m_zero = cv::imread("CSC_0113.JPG", CV_LOAD_IMAGE_COLOR);
        m_zero = cv::imread(filename.toStdString(), CV_LOAD_IMAGE_COLOR);
    

    The code works, and the MsgBox displays the height of the matrix m_zero
    I have done several searches but I can not find a solution.

    cordially


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Don't have other warnings about the existence of some of the libraries you are linking to ? (e.g. libwebp)





  • In case when i use a Opencv non static library , i have this problem

    "Le programme s'est terminé subitement." french
    "The program ended suddenly." 
    

  • Lifetime Qt Champion

    Dod you have the OpenCV .dlls folder in your PATH environment variable ? If not then go to the Run part of the Project panel and add it there (do not do it system wide).



  • @SGaist
    yes all opencv files is included in the path.
    After some research in log file, i think I have a problème with the génération of libopencv_imgcodecs310 and libopencv_imgproc310 files.

    I'll keep you posted.


Log in to reply
 

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