Results 1 to 6 of 6

Thread: Using external dll in Qt [OpenCV]

  1. #1
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using external dll in Qt [OpenCV]

    Hello!

    I have a problem with integrating QtCreator with OpenCV. I've build the OpenCV correctly, source path is:
    C:\Programs\OpenCV-2.4.2\opencv
    and build path is:
    C:\Programs\OpenCV-2.4.2\mybuild

    First of all, I wanted to use the video capture, so I add in *.pro
    Qt Code:
    1. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/opencv/build/include
    2. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuild/bin/Debug/ -lopencv_highgui242d
    3. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuild/lib/Debug/ -lopencv_highgui242d
    To copy to clipboard, switch view to plain text mode 

    And something went wrong, because highgui.hpp was added corectly to main heder file, but when I try to use:
    Qt Code:
    1. cv::VideoCapture capWebCam;
    To copy to clipboard, switch view to plain text mode 
    Qt said:
    Qt Code:
    1. undefined reference to `cv::VideoCapture::VideoCapture()'
    To copy to clipboard, switch view to plain text mode 

    How can I fix it?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using external dll in Qt [OpenCV]

    Qt didn't say that. Your linker did. You fix it by linking the OpenCV library that contains cv::VideoCapture, which ever that is. It may be you have the right library but wrong library search path so look at all the relevant linker output for mentions of unfound libraries etc.

  3. #3
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using external dll in Qt [OpenCV]

    But, it's happening even if I add all libraries found in "lib/Debug/"...

  4. #4
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using external dll in Qt [OpenCV]

    Hello again!

    After hours of battle with Qt and OpenCV and thousand of web sites I've found the solution to the previous problem. It appers, that my Qt compiler is MinGW and I build OpenCV with MVSC+ and I think it was the couse of problem.

    But now I have another problem. I have only one line:
    Qt Code:
    1. cv::VideoCapture capWebCam;
    To copy to clipboard, switch view to plain text mode 

    And after building it everything is fine, but afer run I got massage:
    Qt Code:
    1. exited with code -1073741511
    To copy to clipboard, switch view to plain text mode 

    If I go to the project folder and try to execute the program, this one in release folder shows "Program stopped working", but this one from debug folder works fine (but don't do enything, because in constructor is only the line above).

    I've read that -1073741511 code is connected with dll linking. But in folder of builded binary OpenCV-2.4.2 files is folder "bin", where are all *.dll's, and that's what I link to the program with:
    Qt Code:
    1. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/mybuildmingw/install/include
    2.  
    3. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuildmingw/install/bin -llibopencv_highgui242
    4. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuildmingw/install/lib -llibopencv_highgui242
    To copy to clipboard, switch view to plain text mode 

    So, what do I do wrong? Can someone help me?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Using external dll in Qt [OpenCV]

    The contents of the PRO file, INCLUDEPATH and LIBS, are to do with compiling and linking your code in to the final executable. Once compiled this file plays no part.

    At run time your program must be able to locate the OpenCV DLLs in one of the usual places that Windows look is given the environment the program is run in. These places are generally: the same directory as the executable, somewhere in the directories listed in the PATH environment variable, or the Windows folders.

    If you are running from an IDE you can use the IDE to set the run time environment the program is launched in. In Qt Creator: Projects, Targets, Desktop/Run, Run Environment.

    If you are running outside the IDE then you should place the OpenCV directory into the system (or user) PATH.

  6. #6
    Join Date
    Oct 2012
    Location
    Warsaw,Poland
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using external dll in Qt [OpenCV]

    OpenCV DLL's are placed only in PATH environment variable, I mean:
    Qt Code:
    1. C:\Programs\OpenCV-2.4.2\mybuildmingw\install\bin
    To copy to clipboard, switch view to plain text mode 
    I added this line too:
    Qt Code:
    1. C:\Programs\OpenCV-2.4.2\mybuildmingw\install\lib
    To copy to clipboard, switch view to plain text mode 
    Where "mybuildmingw" is folder with complied OpenCV files with MinGW.

    And in *.pro file I have:
    Qt Code:
    1. INCLUDEPATH += C:/Programy/OpenCV-2.4.2/mybuildmingw/install/include
    2.  
    3. LIBS += -LC:/Programy/OpenCV-2.4.2/mybuildmingw/install/bin -llibopencv_highgui242
    4. LIBS += -LC:/Programy/OpenCV-2.4.2/mybuildmingw/install/lib -llibopencv_highgui242
    To copy to clipboard, switch view to plain text mode 

    So, that was what are you talking about?

    ================================================== =========================
    EDIT:
    I've solved the problem, but it's the most weirdest thing I've ever meet in programming... I have nothing connected with OpenCV in PATH environment variable and my *.pro file is:
    Qt Code:
    1. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/mybuildmingw/install/include
    2. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/mybuildmingw/install/include/opencv
    3.  
    4. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuild/lib/Debug -lopencv_highgui242d \
    5. -lopencv_core242d
    To copy to clipboard, switch view to plain text mode 

    So: "mybuildmingw" is folder with compiled OpenCV files with MinGW and "mybuild" is folder with compiled OpenCV files with MVSC+... Include files Qt takes from MinGW build and lib's from MVSC+ build. It's so weird, but it's working!

    Qt Code:
    1. #include <opencv2/core/core.hpp>
    2. #include <opencv2/imgproc/imgproc.hpp>
    3. #include <opencv2/highgui/highgui.hpp>
    4. ...
    5. IplImage* img = cvLoadImage( "C:\\opencv.png" );
    6. cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    7. cvShowImage("Example1", img);
    8. cvWaitKey(0);
    To copy to clipboard, switch view to plain text mode 

    ================================================== =========================
    EDIT2:

    It's not so simple as I thought. I have another linker problem:

    Qt Code:
    1. #include <opencv2/core/core.hpp>
    2. #include <opencv2/imgproc/imgproc.hpp>
    3. #include <opencv2/highgui/highgui.hpp>
    4. ...
    5. IplImage* img = cvLoadImage( "C:\\opencv.png" );
    6. cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    7. cvShowImage("Example1", img);
    8. cvWaitKey(0);
    9.  
    10. cv::VideoCapture capture(0);
    To copy to clipboard, switch view to plain text mode 

    And *.pro:
    Qt Code:
    1. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/mybuildmingw/install/include
    2. INCLUDEPATH += C:/Programs/OpenCV-2.4.2/mybuildmingw/install/include/opencv
    3.  
    4. LIBS += -LC:/Programs/OpenCV-2.4.2/mybuild/lib/Debug \
    5. -lopencv_calib3d242d \
    6. -lopencv_contrib242d \
    7. -lopencv_core242d \
    8. -lopencv_features2d242d \
    9. -lopencv_flann242d \
    10. -lopencv_gpu242d \
    11. -lopencv_haartraining_engined \
    12. -lopencv_highgui242d \
    13. -lopencv_imgproc242d \
    14. -lopencv_legacy242d \
    15. -lopencv_ml242d \
    16. -lopencv_nonfree242d \
    17. -lopencv_objdetect242d \
    18. -lopencv_photo242d \
    19. -lopencv_stitching242d \
    20. -lopencv_ts242d \
    21. -lopencv_video242d \
    22. -lopencv_videostab242d
    To copy to clipboard, switch view to plain text mode 

    And error occurs:
    Qt Code:
    1. (...) undefined reference to `cv::VideoCapture::VideoCapture(int)'
    2. (...) undefined reference to `cv::VideoCapture::~VideoCapture()'
    3. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    Any ideas?
    Last edited by danioto; 29th October 2012 at 01:39.

Similar Threads

  1. OpenCV + QT4
    By thereisnoknife in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2013, 05:19
  2. OpenCV on mac
    By sandeep_hyd123 in forum Newbie
    Replies: 1
    Last Post: 17th June 2011, 04:53
  3. opencv-qt-mac
    By ireneluis in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2010, 15:24
  4. JAI vs. OpenCV vs. ITK
    By tpieciak in forum General Programming
    Replies: 0
    Last Post: 8th July 2009, 13:45
  5. OpenCv + Qt
    By Janderson Borges in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2008, 13:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.