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. Cross compile OpenCV to a RaspberryPI
Forum Updated to NodeBB v4.3 + New Features

Cross compile OpenCV to a RaspberryPI

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 3.4k Views 1 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.
  • H hamzaelazizi
    11 May 2022, 09:50

    @JonB in case i was able to find its location, how can i tell Qt Creator to look for that library in that path ?

    J Offline
    J Offline
    JonB
    wrote on 11 May 2022, 09:52 last edited by
    #15

    @hamzaelazizi
    I have updated my post to give you a Linux find command to help you locate it.
    Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
    I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

    H 2 Replies Last reply 11 May 2022, 10:04
    0
    • J JonB
      11 May 2022, 09:52

      @hamzaelazizi
      I have updated my post to give you a Linux find command to help you locate it.
      Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
      I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

      H Offline
      H Offline
      hamzaelazizi
      wrote on 11 May 2022, 10:04 last edited by
      #16

      @JonB it gave me all these locations:

      /home/rnsaoberon/rpi-qt/tools/cross-pi-gcc-8.3.0-2/arm-linux-gnueabihf/libc/usr/lib/libm.a
      /home/rnsaoberon/rpi-qt/sysroot/lib/arm-linux-gnueabihf/libm.a
      /home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf/libm.a
      /usr/arm-linux-gnueabi/libhf/libm.a
      /usr/lib/x86_64-linux-gnu/libm.a
      /usr/arm-linux-gnueabihf/lib/libm.a

      i used the one with the Bold writing

      1 Reply Last reply
      0
      • J JonB
        11 May 2022, 09:52

        @hamzaelazizi
        I have updated my post to give you a Linux find command to help you locate it.
        Let's see where, if anywhere, it tells you it finds it before we know how to proceed.
        I don't do cross-compilation so I don't know where you need to look or what to do about it when you find it, you may need @jsulm's help when you have told us where it is....

        H Offline
        H Offline
        hamzaelazizi
        wrote on 11 May 2022, 10:19 last edited by
        #17

        @JonB after i included the one i told you about i started having other errors :

        undefined reference to cv::imshow
        undefined reference to cv::imread undefined reference to cv::wait
        undefined reference to `cv::Mat

        J 1 Reply Last reply 11 May 2022, 10:20
        0
        • H hamzaelazizi
          11 May 2022, 10:19

          @JonB after i included the one i told you about i started having other errors :

          undefined reference to cv::imshow
          undefined reference to cv::imread undefined reference to cv::wait
          undefined reference to `cv::Mat

          J Offline
          J Offline
          JonB
          wrote on 11 May 2022, 10:20 last edited by
          #18

          @hamzaelazizi
          As I said, since I know nothing about cross-compilation or RPi you will have to await a comment from e.g. @jsulm as to what you are supposed to do....

          H 1 Reply Last reply 11 May 2022, 10:29
          0
          • J JonB
            11 May 2022, 10:20

            @hamzaelazizi
            As I said, since I know nothing about cross-compilation or RPi you will have to await a comment from e.g. @jsulm as to what you are supposed to do....

            H Offline
            H Offline
            hamzaelazizi
            wrote on 11 May 2022, 10:29 last edited by
            #19

            @JonB Okey i'll be waiting for him to reply back, hopefully he does

            J 1 Reply Last reply 11 May 2022, 11:02
            0
            • H hamzaelazizi
              11 May 2022, 10:29

              @JonB Okey i'll be waiting for him to reply back, hopefully he does

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 11 May 2022, 11:02 last edited by
              #20

              @hamzaelazizi Try this (add it to your pro file):

              LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
              

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

              H 1 Reply Last reply 11 May 2022, 11:08
              2
              • J jsulm
                11 May 2022, 11:02

                @hamzaelazizi Try this (add it to your pro file):

                LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
                
                H Offline
                H Offline
                hamzaelazizi
                wrote on 11 May 2022, 11:08 last edited by
                #21

                @jsulm yes i changed the path to the one i have and it worked but it then started showing these different errors :

                undefined reference to cv::imshow
                undefined reference to cv::imread
                undefined reference to cv::wait
                undefined reference to cv::Mat

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  hamzaelazizi
                  wrote on 11 May 2022, 11:19 last edited by
                  #22

                  here's my .pro file code :

                  TEMPLATE = app
                  CONFIG += console c++11
                  CONFIG -= app_bundle
                  CONFIG -= qt
                  
                  INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                  #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                  
                  QT_CONFIG -= no-pkg-config
                  
                  LIBS += `pkg-config --cflags --libs opencv4`
                  
                  LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm
                  #CONFIG += link_pkgconfig
                  #PKGCONFIG += opencv4
                  
                  SOURCES += \
                          main.cpp
                  
                  # Default rules for deployment.
                  qnx: target.path = /tmp/$${TARGET}/bin
                  else: unix:!android: target.path = /home/pi/$${TARGET}
                  !isEmpty(target.path): INSTALLS += target
                  

                  and here's my main c++ code :

                  #include <opencv2/highgui.hpp>
                  
                  int main()
                  {
                      cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg");
                      cv::imshow("Window",img);
                      cv::waitKey(0);
                  
                      return 0;
                  }
                  
                  J J 2 Replies Last reply 11 May 2022, 11:35
                  0
                  • H hamzaelazizi
                    11 May 2022, 11:19

                    here's my .pro file code :

                    TEMPLATE = app
                    CONFIG += console c++11
                    CONFIG -= app_bundle
                    CONFIG -= qt
                    
                    INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                    #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                    
                    QT_CONFIG -= no-pkg-config
                    
                    LIBS += `pkg-config --cflags --libs opencv4`
                    
                    LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm
                    #CONFIG += link_pkgconfig
                    #PKGCONFIG += opencv4
                    
                    SOURCES += \
                            main.cpp
                    
                    # Default rules for deployment.
                    qnx: target.path = /tmp/$${TARGET}/bin
                    else: unix:!android: target.path = /home/pi/$${TARGET}
                    !isEmpty(target.path): INSTALLS += target
                    

                    and here's my main c++ code :

                    #include <opencv2/highgui.hpp>
                    
                    int main()
                    {
                        cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg");
                        cv::imshow("Window",img);
                        cv::waitKey(0);
                    
                        return 0;
                    }
                    
                    J Offline
                    J Offline
                    JonB
                    wrote on 11 May 2022, 11:35 last edited by JonB 5 Nov 2022, 11:43
                    #23

                    @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                    LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm

                    While you await @jsulm who actually knows something about this...!

                    I believe you are saying:

                    • without -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf, although it cannot find the -lm library, you do not get errors undefined reference to cv::..., right?
                    • with -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf, it finds the math library, but you do get errors undefined reference to cv::..., right?

                    In that case, by putting /home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf high on the library directory search list the cv::... stuff it also needs is no longer found, because it must find some different cv library archives (in that specified directory) instead of what it used to find, and those libraries do not include something which would resolve those references.

                    What you do/are supposed to do with that I do not know.....

                    UPDATE
                    Oh, maybe not. Those "undefined"s may always have been there. But when it cannot resolve the -lm on the link line it will stop there and won't get as far as the final step of linkage where it would notice undefineds. So the -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf may be nothing to do with the "undefined"s....

                    You might start by running pkg-config --cflags --libs opencv4 in a terminal, to at least see what that is producing. E.g. if that is not even outputting any library paths to put into your LIBS it's not right....

                    H 1 Reply Last reply 11 May 2022, 11:58
                    1
                    • H hamzaelazizi
                      11 May 2022, 11:19

                      here's my .pro file code :

                      TEMPLATE = app
                      CONFIG += console c++11
                      CONFIG -= app_bundle
                      CONFIG -= qt
                      
                      INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                      #DEPENDPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4
                      
                      QT_CONFIG -= no-pkg-config
                      
                      LIBS += `pkg-config --cflags --libs opencv4`
                      
                      LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm
                      #CONFIG += link_pkgconfig
                      #PKGCONFIG += opencv4
                      
                      SOURCES += \
                              main.cpp
                      
                      # Default rules for deployment.
                      qnx: target.path = /tmp/$${TARGET}/bin
                      else: unix:!android: target.path = /home/pi/$${TARGET}
                      !isEmpty(target.path): INSTALLS += target
                      

                      and here's my main c++ code :

                      #include <opencv2/highgui.hpp>
                      
                      int main()
                      {
                          cv::Mat img = cv::imread("/home/pi/Pictures/drake.jpg");
                          cv::imshow("Window",img);
                          cv::waitKey(0);
                      
                          return 0;
                      }
                      
                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 11 May 2022, 11:57 last edited by
                      #24

                      @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                      INCLUDEPATH += /home/rnsaoberon/rpi-qt/sysroot/usr/local/include/opencv4

                      Please change all these paths!
                      You do NOT have to put the path of your sysroot!
                      It should look like this:

                      INCLUDEPATH += /usr/local/include/opencv4
                      

                      Also, why /usr/local?! I doubt OpenCV packages from your OS install anything in /usr/local! Please fix this!

                      "LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm" - this is also not what I suggested! Why do you add sysroot path everywhere?

                      LIBS += -L/usr/lib/arm-linux-gnueabihf -lm
                      

                      The errors you posted mean that OpenCV libs are not found. If you really install OpenCV using your OS packet manager on your RaspberryPi the libs should be somewhere in /usr/lib and it should be enough to add -lLIBNAME to pro file.

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

                      1 Reply Last reply
                      3
                      • J JonB
                        11 May 2022, 11:35

                        @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                        LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf -lm

                        While you await @jsulm who actually knows something about this...!

                        I believe you are saying:

                        • without -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf, although it cannot find the -lm library, you do not get errors undefined reference to cv::..., right?
                        • with -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf, it finds the math library, but you do get errors undefined reference to cv::..., right?

                        In that case, by putting /home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf high on the library directory search list the cv::... stuff it also needs is no longer found, because it must find some different cv library archives (in that specified directory) instead of what it used to find, and those libraries do not include something which would resolve those references.

                        What you do/are supposed to do with that I do not know.....

                        UPDATE
                        Oh, maybe not. Those "undefined"s may always have been there. But when it cannot resolve the -lm on the link line it will stop there and won't get as far as the final step of linkage where it would notice undefineds. So the -L/home/rnsaoberon/rpi-qt/sysroot/usr/lib/arm-linux-gnueabihf may be nothing to do with the "undefined"s....

                        You might start by running pkg-config --cflags --libs opencv4 in a terminal, to at least see what that is producing. E.g. if that is not even outputting any library paths to put into your LIBS it's not right....

                        H Offline
                        H Offline
                        hamzaelazizi
                        wrote on 11 May 2022, 11:58 last edited by
                        #25

                        @JonB i think i have got it to work, and i'm still in shock...

                        i added this code in .pro file : LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs

                        Apparently, Qt Creator wasn't able to find the libraries necessary for the application, so when i asked it to add them, it worked !
                        Tho, i'm sure i'll encounter more problems in the near futur, but that's enouh errors for one day.
                        i still have one question which is irrelevant to this topic : How can i use Qt to work with a thermal camera that uses SPI(GPIO) protocol to communicate. a FLIR Lepton thermal camera to be specific, Thank you !

                        J 1 Reply Last reply 11 May 2022, 11:59
                        0
                        • H hamzaelazizi
                          11 May 2022, 11:58

                          @JonB i think i have got it to work, and i'm still in shock...

                          i added this code in .pro file : LIBS += -L/home/rnsaoberon/rpi-qt/sysroot/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs

                          Apparently, Qt Creator wasn't able to find the libraries necessary for the application, so when i asked it to add them, it worked !
                          Tho, i'm sure i'll encounter more problems in the near futur, but that's enouh errors for one day.
                          i still have one question which is irrelevant to this topic : How can i use Qt to work with a thermal camera that uses SPI(GPIO) protocol to communicate. a FLIR Lepton thermal camera to be specific, Thank you !

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 11 May 2022, 11:59 last edited by
                          #26

                          @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                          Apparently, Qt Creator wasn't able to find the libraries necessary for the application

                          Well, you have to tell the build system (not QtCreator) which libs your app needs, there is no magic.
                          Please also consider my previous post.

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

                          H 1 Reply Last reply 11 May 2022, 12:12
                          3
                          • J jsulm
                            11 May 2022, 11:59

                            @hamzaelazizi said in Cross compile OpenCV to a RaspberryPI:

                            Apparently, Qt Creator wasn't able to find the libraries necessary for the application

                            Well, you have to tell the build system (not QtCreator) which libs your app needs, there is no magic.
                            Please also consider my previous post.

                            H Offline
                            H Offline
                            hamzaelazizi
                            wrote on 11 May 2022, 12:12 last edited by
                            #27

                            @jsulm Thank you for your time and effort, sir ! much appreciated

                            1 Reply Last reply
                            0

                            24/27

                            11 May 2022, 11:57

                            • Login

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