Qt5 and OpenCv 4












1















I want to use the OpenCv framework with Qt Applications on Linux (Debian). From https://opencv.org/releases.html I've downloaded the opencv-4.0.1.zip and unzip it into a folder. Then using CMake GUI I've configured the build with BUILD_opencv_world option marked. Then I generate the build and with compiled the library with make and make install and everything seems to be fine.



I've created a opencv.pri file with:



INCLUDE += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_world


To test OpenCv I've created a Qt command line project and try to load an image and display, here the QtCvTest.pro



QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked 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 += main.cpp

include(/home/stefano/opencv-4.0.1/opencv.pri)


and main.cpp



#include <QCoreApplication>
#include <QDebug>

#include <opencv2/opencv.hpp>

int main(int argc, char *argv)
{
QCoreApplication a(argc, argv);

qDebug() << "QtCvTest Start";

using namespace cv;

Mat image;
image = imread("/home/stefano/Pictures/2018/02/27/DSC_1421.JPG", CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
qDebug() << "Could not open or find the image";
return -1;
}

namedWindow( "Test", WINDOW_AUTOSIZE );
imshow( "Test", image );


qDebug() << "QtCvTest End";

return a.exec();
}


If I try to compile I get the following error



main.cpp:22: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'


any idea how to solve this error?



Thanks in advance for your help










share|improve this question


















  • 1





    change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

    – eyllanesc
    Jan 1 at 20:49













  • Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

    – eyllanesc
    Jan 1 at 20:49











  • Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

    – Stefano
    Jan 1 at 22:32













  • It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

    – eyllanesc
    Jan 1 at 22:34






  • 1





    with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

    – eyllanesc
    Jan 1 at 22:41


















1















I want to use the OpenCv framework with Qt Applications on Linux (Debian). From https://opencv.org/releases.html I've downloaded the opencv-4.0.1.zip and unzip it into a folder. Then using CMake GUI I've configured the build with BUILD_opencv_world option marked. Then I generate the build and with compiled the library with make and make install and everything seems to be fine.



I've created a opencv.pri file with:



INCLUDE += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_world


To test OpenCv I've created a Qt command line project and try to load an image and display, here the QtCvTest.pro



QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked 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 += main.cpp

include(/home/stefano/opencv-4.0.1/opencv.pri)


and main.cpp



#include <QCoreApplication>
#include <QDebug>

#include <opencv2/opencv.hpp>

int main(int argc, char *argv)
{
QCoreApplication a(argc, argv);

qDebug() << "QtCvTest Start";

using namespace cv;

Mat image;
image = imread("/home/stefano/Pictures/2018/02/27/DSC_1421.JPG", CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
qDebug() << "Could not open or find the image";
return -1;
}

namedWindow( "Test", WINDOW_AUTOSIZE );
imshow( "Test", image );


qDebug() << "QtCvTest End";

return a.exec();
}


If I try to compile I get the following error



main.cpp:22: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'


any idea how to solve this error?



Thanks in advance for your help










share|improve this question


















  • 1





    change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

    – eyllanesc
    Jan 1 at 20:49













  • Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

    – eyllanesc
    Jan 1 at 20:49











  • Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

    – Stefano
    Jan 1 at 22:32













  • It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

    – eyllanesc
    Jan 1 at 22:34






  • 1





    with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

    – eyllanesc
    Jan 1 at 22:41
















1












1








1








I want to use the OpenCv framework with Qt Applications on Linux (Debian). From https://opencv.org/releases.html I've downloaded the opencv-4.0.1.zip and unzip it into a folder. Then using CMake GUI I've configured the build with BUILD_opencv_world option marked. Then I generate the build and with compiled the library with make and make install and everything seems to be fine.



I've created a opencv.pri file with:



INCLUDE += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_world


To test OpenCv I've created a Qt command line project and try to load an image and display, here the QtCvTest.pro



QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked 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 += main.cpp

include(/home/stefano/opencv-4.0.1/opencv.pri)


and main.cpp



#include <QCoreApplication>
#include <QDebug>

#include <opencv2/opencv.hpp>

int main(int argc, char *argv)
{
QCoreApplication a(argc, argv);

qDebug() << "QtCvTest Start";

using namespace cv;

Mat image;
image = imread("/home/stefano/Pictures/2018/02/27/DSC_1421.JPG", CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
qDebug() << "Could not open or find the image";
return -1;
}

namedWindow( "Test", WINDOW_AUTOSIZE );
imshow( "Test", image );


qDebug() << "QtCvTest End";

return a.exec();
}


If I try to compile I get the following error



main.cpp:22: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'


any idea how to solve this error?



Thanks in advance for your help










share|improve this question














I want to use the OpenCv framework with Qt Applications on Linux (Debian). From https://opencv.org/releases.html I've downloaded the opencv-4.0.1.zip and unzip it into a folder. Then using CMake GUI I've configured the build with BUILD_opencv_world option marked. Then I generate the build and with compiled the library with make and make install and everything seems to be fine.



I've created a opencv.pri file with:



INCLUDE += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_world


To test OpenCv I've created a Qt command line project and try to load an image and display, here the QtCvTest.pro



QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked 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 += main.cpp

include(/home/stefano/opencv-4.0.1/opencv.pri)


and main.cpp



#include <QCoreApplication>
#include <QDebug>

#include <opencv2/opencv.hpp>

int main(int argc, char *argv)
{
QCoreApplication a(argc, argv);

qDebug() << "QtCvTest Start";

using namespace cv;

Mat image;
image = imread("/home/stefano/Pictures/2018/02/27/DSC_1421.JPG", CV_LOAD_IMAGE_COLOR);
if(! image.data ) {
qDebug() << "Could not open or find the image";
return -1;
}

namedWindow( "Test", WINDOW_AUTOSIZE );
imshow( "Test", image );


qDebug() << "QtCvTest End";

return a.exec();
}


If I try to compile I get the following error



main.cpp:22: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'


any idea how to solve this error?



Thanks in advance for your help







c++ qt opencv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 20:19









StefanoStefano

438




438








  • 1





    change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

    – eyllanesc
    Jan 1 at 20:49













  • Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

    – eyllanesc
    Jan 1 at 20:49











  • Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

    – Stefano
    Jan 1 at 22:32













  • It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

    – eyllanesc
    Jan 1 at 22:34






  • 1





    with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

    – eyllanesc
    Jan 1 at 22:41
















  • 1





    change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

    – eyllanesc
    Jan 1 at 20:49













  • Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

    – eyllanesc
    Jan 1 at 20:49











  • Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

    – Stefano
    Jan 1 at 22:32













  • It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

    – eyllanesc
    Jan 1 at 22:34






  • 1





    with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

    – eyllanesc
    Jan 1 at 22:41










1




1





change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

– eyllanesc
Jan 1 at 20:49







change INCLUDE to INCLUDEPATH, change -lopencv_world to -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs

– eyllanesc
Jan 1 at 20:49















Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

– eyllanesc
Jan 1 at 20:49





Or use: CONFIG += link_pkgconfig PKGCONFIG += opencv4

– eyllanesc
Jan 1 at 20:49













Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

– Stefano
Jan 1 at 22:32







Now it works! I've changed to INCLUDEPATH and added the link to opencv_imgproc, opencv_core and opencv_highgui. If I add also opencv_imgcodecs I get an error (-1: error: cannot find -lopencv_imgcodecs). Thanks a lot for your help!

– Stefano
Jan 1 at 22:32















It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

– eyllanesc
Jan 1 at 22:34





It seems that when you compiled you did not disable a flag that compiles that binary, it does not matter

– eyllanesc
Jan 1 at 22:34




1




1





with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

– eyllanesc
Jan 1 at 22:41







with PKGCONFIG + = opencv you are adding all the -l{libs} so your executable is probably very heavy unlike if you add one by one as in the first case so for development use PKGCONFIG and for production I only link the necessary ones.

– eyllanesc
Jan 1 at 22:41














1 Answer
1






active

oldest

votes


















1














You have to use INCLUDEPATH and the necessary flags for reading and displaying the image in a window:



INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_core -lopencv_highgui





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998648%2fqt5-and-opencv-4%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You have to use INCLUDEPATH and the necessary flags for reading and displaying the image in a window:



    INCLUDEPATH += /usr/local/include
    LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_core -lopencv_highgui





    share|improve this answer




























      1














      You have to use INCLUDEPATH and the necessary flags for reading and displaying the image in a window:



      INCLUDEPATH += /usr/local/include
      LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_core -lopencv_highgui





      share|improve this answer


























        1












        1








        1







        You have to use INCLUDEPATH and the necessary flags for reading and displaying the image in a window:



        INCLUDEPATH += /usr/local/include
        LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_core -lopencv_highgui





        share|improve this answer













        You have to use INCLUDEPATH and the necessary flags for reading and displaying the image in a window:



        INCLUDEPATH += /usr/local/include
        LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_core -lopencv_highgui






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 22:35









        eyllanesceyllanesc

        82.3k103259




        82.3k103259
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998648%2fqt5-and-opencv-4%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter