Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why after linking the OpenCV libraries, Mat objects are still 'undefined'?
Qt 6.11 is out! See what's new in the release blog

Why after linking the OpenCV libraries, Mat objects are still 'undefined'?

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 5 Posters 9.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS SGaist

    How did you install OpenCV ?
    Did you check that it is from the correct architecture ?

    G Offline
    G Offline
    georgiav
    wrote on last edited by
    #9

    @SGaist I was checking now, I'm using it from the virtual machine provided by my university. The path seemed fine when I was compiling the program from a shell so I'm not sure what's wrong. What should I look for ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #10

      Call "file /usr/local/lib/libopencv_core.so". What do you get ?

      As for your .pro file:

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

      should be enough to link to these OpenCV libraries.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • G Offline
        G Offline
        georgiav
        wrote on last edited by
        #11

        @SGaist It was a 'symbolic link' to libopencv_imgproc.so.4.5.0, so I called it again for that and got:
        file /usr/local/lib/libopencv_imgproc.so.4.5.0
        /usr/local/lib/libopencv_imgproc.so.4.5.0: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=a9e4463d8bcc7f5051819e1ab34a131be7685cb3, not stripped

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #12

          Can you show your current .pro file content ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you show your current .pro file content ?

            G Offline
            G Offline
            georgiav
            wrote on last edited by
            #13

            @SGaist yes :
            QT += core gui
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

               CONFIG += c++11
               
               # 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 += \
                   core.cpp \
                   main.cpp \
                   mainwindow.cpp
               
               HEADERS += \
                   mainwindow.h
               
               FORMS += \
                   mainwindow.ui
               
               INCLUDEPATH += -I/usr/local/include
               LIBS += -L/usr/local/lib \
                       -lopencv_core \
                       -lopencv_highgui \
                       -lopencv_imgproc
               
               # Default rules for deployment.
               qnx: target.path = /tmp/$${TARGET}/bin
               else: unix:!android: target.path = /opt/$${TARGET}/bin
               !isEmpty(target.path): INSTALLS += target
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #14

              That looks good. What exact error are you getting now, after doing a full rebuild ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • G Offline
                G Offline
                georgiav
                wrote on last edited by
                #15

                c9a4fb04-6f12-48fb-b3ab-ec4e0ccfb27d-image.png

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  That's not a linking problem you have there.

                  Where is opencv2/core.hpp located exactly in your system ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    georgiav
                    wrote on last edited by
                    #17

                    699f50b9-ef3e-4929-92bd-81e2a12f5de2-image.png

                    it should be the one on top left right? given the path

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #18

                      Did you notice the "opencv4" folder that is missing from your INCLUDEPATH statement ?

                      Either add it there or to your include statements.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • G Offline
                        G Offline
                        georgiav
                        wrote on last edited by
                        #19

                        I tried that and it still doesn't work apparently

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #20

                          Please provide the information directly.
                          What exactly did you try ?
                          What is the error your get ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            georgiav
                            wrote on last edited by
                            #21

                            26ceb0ba-dae5-4681-8b11-162566e5631e-image.png

                            I changed the include statements to that and in the .pro file the INCLUDEPATH is /usr/local/include/opencv4

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #22

                              @SGaist said in Why after linking the OpenCV libraries, Mat objects are still 'undefined'?:

                              Did you notice the "opencv4" folder that is missing from your INCLUDEPATH statement ?

                              Either add it there or to your include statements.

                              I wrote "either" which means one or the other, not both.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                georgiav
                                wrote on last edited by
                                #23

                                3f160844-42c9-4164-989a-ba6571a57158-image.png

                                So I changed it in the main.cpp file because otherwise I got those errors . Now in the .pro file is /usr/local/include.
                                I still get the same errors
                                7c81d5f1-be9e-46f3-8e4f-cb4ea697577b-image.png

                                The last error I don't understand because I wrote opencv2/core/core.hpp not opencv2/core.hpp and I cleaned the project again before

                                jsulmJ 1 Reply Last reply
                                0
                                • G georgiav

                                  3f160844-42c9-4164-989a-ba6571a57158-image.png

                                  So I changed it in the main.cpp file because otherwise I got those errors . Now in the .pro file is /usr/local/include.
                                  I still get the same errors
                                  7c81d5f1-be9e-46f3-8e4f-cb4ea697577b-image.png

                                  The last error I don't understand because I wrote opencv2/core/core.hpp not opencv2/core.hpp and I cleaned the project again before

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #24

                                  @georgiav Change INCLUDEPATH in your pro file so, that it points to /usr/local/include/opencv4 and change your includes like

                                  #include "opencv2/...
                                  

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  G 1 Reply Last reply
                                  2
                                  • jsulmJ jsulm

                                    @georgiav Change INCLUDEPATH in your pro file so, that it points to /usr/local/include/opencv4 and change your includes like

                                    #include "opencv2/...
                                    
                                    G Offline
                                    G Offline
                                    georgiav
                                    wrote on last edited by
                                    #25

                                    @jsulm Hi, I tried that before and I got those errors of 'file not found' ( photo above)

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #26

                                      Here is a minimal example adjusted to the paths you shown to us:

                                      .pro file:

                                      TEMPLATE = app
                                      TARGET = test_opencv
                                      INCLUDEPATH += .
                                      INCLUDEPATH += /usr/local/include/opencv4
                                       
                                      LIBS += -L/usr/local/lib/ -lopencv_core
                                      SOURCES += main.cpp
                                      

                                      main.cpp:

                                       #include <opencv2/core.hpp>
                                        
                                       int main(int argc, char **argv)
                                       {
                                            cv::Mat mat;
                                            return 0;
                                       }
                                      

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      G 1 Reply Last reply
                                      1
                                      • SGaistS SGaist

                                        Here is a minimal example adjusted to the paths you shown to us:

                                        .pro file:

                                        TEMPLATE = app
                                        TARGET = test_opencv
                                        INCLUDEPATH += .
                                        INCLUDEPATH += /usr/local/include/opencv4
                                         
                                        LIBS += -L/usr/local/lib/ -lopencv_core
                                        SOURCES += main.cpp
                                        

                                        main.cpp:

                                         #include <opencv2/core.hpp>
                                          
                                         int main(int argc, char **argv)
                                         {
                                              cv::Mat mat;
                                              return 0;
                                         }
                                        
                                        G Offline
                                        G Offline
                                        georgiav
                                        wrote on last edited by
                                        #27

                                        @SGaist Yes, this seems to work fine! Thank you very much!

                                        Pablo J. RoginaP 1 Reply Last reply
                                        0
                                        • G georgiav

                                          @SGaist Yes, this seems to work fine! Thank you very much!

                                          Pablo J. RoginaP Offline
                                          Pablo J. RoginaP Offline
                                          Pablo J. Rogina
                                          wrote on last edited by
                                          #28

                                          @georgiav said in Why after linking the OpenCV libraries, Mat objects are still 'undefined'?:

                                          this seems to work fine!

                                          so please don't forget to mark your post as solved!

                                          Upvote the answer(s) that helped you solve the issue
                                          Use "Topic Tools" button to mark your post as Solved
                                          Add screenshots via postimage.org
                                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                          1 Reply Last reply
                                          0
                                          • M Matiyash referenced this topic on

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved