Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: Qt + OpenCV, simple example

  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Qt + OpenCV, simple example

    Hi,

    today I've found my old project I wrote some time ago. This is simple application that uses OpenCV to capture images from camera or video, optionally process them and displays in QLabel. I've decided to share it with community, made the code more self-explanatory, added some comments, especially explaining BGR24 IplImage to QImage conversion stuff (it can be done easier, but I think its better this way for "educational" purposes).
    This app does not use separate threads for capturing or processing images, I think everything is as simple as possible.
    I've seen many posts about using basic OpenCV with Qt, so maybe this will be useful for some "newbies".

    I hope this helps someone.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by stampede; 11th July 2011 at 23:58.

  2. The following 5 users say thank you to stampede for this useful post:

    andre_teprom (26th July 2013), harley (1st September 2011), ikmqt (28th August 2012), Ksenia (15th October 2013), mvuori (12th July 2011)

  3. #2
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi Stampede,
    I'm new to QT and opencv, I'm tring to learn to use QT and opencv by following the example given by the book. But I have problem in pointing the directory. So I search and found your free example application. I have installed Opencv2.3 and I tried to edit the project file...and just want to see if it will run..but still I have the similar problem.
    Qt Code:
    1. TEMPLATE = app
    2. DESTDIR = bin
    3. TARGET = cvexample
    4. DEPENDPATH += . src/cpp src/h src/ui
    5. INCLUDEPATH += . src/h
    6.  
    7. UI_DIR = build
    8. MOC_DIR = build
    9.  
    10. build_pass:CONFIG(debug, debug|release){
    11. OBJECTS_DIR = build/debug
    12. } else{
    13. OBJECTS_DIR = build/release
    14. }
    15.  
    16. win32 {
    17. CV11_INCLUDE = C:/OpenCV2.3
    18. CV11_LIB = C:/OpenCV2.3/lib
    19. CV22_INCLUDE = C:/OpenCV2.3/modules
    20. CV22_LIB = C:/OpenCV2.3/build/bin
    21. } else{
    22. CV11_INCLUDE = /usr/local/include/OpenCV
    23. CV11_LIB = /usr/local/lib/OpenCV
    24. CV22_INCLUDE = /usr/local/include/OpenCV2.3
    25. CV22_LIB = /usr/local/lib/OpenCV2.3
    26. }
    27.  
    28. contains(cv,2){
    29. message(build with opencv 2)
    30. DEFINES += OPEN_CV_22
    31. INCLUDEPATH += $$CV22_INCLUDE/core/include/opencv2.3/core \
    32. $$CV22_INCLUDE/highgui/include/opencv2.3/highgui \
    33. $$CV22_INCLUDE/imgproc/include/opencv2.3/imgproc \
    34. $$CV22_INCLUDE/core/include \
    35. $$CV22_INCLUDE/imgproc/include
    36. LIBS += -L$$CV22_LIB
    37. LIBS += -lopencv_highgui220 -lopencv_core220 -lopencv_imgproc220
    38. } else{
    39. message(build with opencv 1.1)
    40. DEFINES -= OPEN_CV_22
    41. INCLUDEPATH += $$CV11_INCLUDE/cv/include $$CV11_INCLUDE/otherlibs/highgui $$CV11_INCLUDE/cxcore/include
    42. LIBS += -L$$CV11_LIB
    43. LIBS += -lcv -lhighgui -lcxcore
    44. }
    45.  
    46. HEADERS += src/h/ImageCapture.h src/h/MainWidget.h
    47. FORMS += src/ui/MainWidget.ui
    48. SOURCES += src/cpp/ImageCapture.cpp src/cpp/MainWidget.cpp main.cpp
    To copy to clipboard, switch view to plain text mode 
    When I compiled it says "C:\QtCvExample-build-desktop\..\QtCvExample\src\h\ImageCapture.h:16: error: cv.h: No such file or directory"
    I know there are some link in this forum regarding opencv, but still I cant find what I'm looking for.

    thanks in advance,
    lam-ang

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    If you are using OpenCV 2.2 or 2.3, you need to run qmake cv=2 and then make, because by default it will include and link to OpenCV 1.1 (btw. its in README ).
    What does it print when you run qmake ? Probably "build with opencv 1.1", right ?

  5. The following user says thank you to stampede for this useful post:

    andre_teprom (26th July 2013)

  6. #4
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi, thanks..hmm I think I better do some more reading in order follow your suggestion...I appreciate the help. I'll get back, as soon I got it.

    regards,
    lam-ang

  7. #5
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi, I have a question, I appoligize if this is so obvious, but I'm really struggling to learn QT. And I came back to post it here because I feel I'm not going anywhere..I was reading "OpenCV 2 Computer application Porgramming cookbook". The first exercise in the book is to display an image. But I found out my QT and Opencv configuration is not correct. I tried to search into this forum and found this useful example(by stampede) that I will gain from but obviously I dont have any idea how to do the procedure as suggested, I must use qmake and make ( tried to read some document) but I was getting lost ..So here is my question.
    1. How can I configure QT and OpenCv using qmake and make?
    Before trying the "QtCvexample" I want to try to display an image to the screen, please see my attachemnt. I have Qt 4.7.3 and OpenCv2.3 installed

    Thanks in advance,
    lam-ang
    Attached Images Attached Images

  8. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    I don't know what is the directory structure of OpenCV 2.3, but in general you need to specify the path to include directories in INCLUDEPATH variable in .pro file. So if in your code you write
    Qt Code:
    1. #include <opencv2.3/core/core.hpp>
    To copy to clipboard, switch view to plain text mode 
    and the file "core.hpp" is in (for example) "C:/OpenCV2.3/include/opencv2.3/core" directory, then make sure INCLUDEPATH contains "C:/OpenCV2.3/include" directory.
    This is just an example, you need to check the actual paths to your files on disk.


    Added after 1 44 minutes:


    Looks like including and linking to OpenCV libraries can be problematic, so here is a simple how-to. It will work only on 32 bit Windows system, with MinGW g++ compiler. We are going to keep things as simple as possible:
    1) download OpenCV 2.3 "superpack"
    2) double click, extract to : C:\ (it will make OpenCV2.3 subfolder automatically)
    3) use the following main.cpp and .pro files:
    Qt Code:
    1. // main.cpp
    2. #include <opencv2/highgui/highgui.hpp>
    3. #include <opencv2/core/core.hpp>
    4.  
    5. int main(){
    6. cv::Mat image = cv::imread("test.jpg");
    7. cv::namedWindow("My Image");
    8. cv::imshow("My Image", image);
    9. cv::waitKey(-1);
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // project.pro
    2. TEMPLATE = app
    3. QT -= gui
    4. TARGET = SimpleCvApp
    5.  
    6. SOURCES += main.cpp
    7.  
    8. INCLUDEPATH += C:/OpenCV2.3/opencv/modules/core/include \
    9. C:/OpenCV2.3/opencv/modules/highgui/include
    10.  
    11. # you can put the opencv .dll files where you want, this is where they are by default
    12. # if you want to use different compiler or architecture, look for the libraries for your configuration in "OpenCV2.3/build" subfolder
    13. LIBS += -L"C:/OpenCV2.3/build/x86/mingw/bin"
    14. LIBS += -lopencv_core230 -lopencv_highgui230
    To copy to clipboard, switch view to plain text mode 
    4) cd to the project folder, run qmake && make
    5) place test.jpg in the project folder
    6) run debug\SimpleCvApp.exe (or release\SimpleCvApp.exe, depends on what version you compile)
    Last edited by stampede; 15th July 2011 at 17:01.

  9. The following user says thank you to stampede for this useful post:

    andre_teprom (26th July 2013)

  10. #7
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi, thanks for the time helping me out I appreciate it very much. I test compiling the project to check if any problem will arise, but no error concerning the library location. But still have some issues.
    result when compiling:
    Qt Code:
    1. Starting C:\OpenCVProjects\MyQtConsoleProject-build-desktop\debug\MyQtConsoleProject.exe...
    2. C:\OpenCVProjects\MyQtConsoleProject-build-desktop\debug\MyQtConsoleProject.exe exited with code -1073741511
    To copy to clipboard, switch view to plain text mode 
    4. cd to the project folder, run qmake && make - I tried to issue qmake and it gives "qmake is not recognized as internal or external command". Am I missing something?


    regards,
    lam-ang
    Last edited by lam-ang; 16th July 2011 at 04:03.

  11. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    Looks like you need to place the needed opencv dll files in folder where the app .exe is located, or in system PATH.
    I tried to issue qmake and it gives "qmake is not recognized as internal or external command"
    Again, path to folder with qmake.exe shoud be in PATH env. variable.

  12. The following user says thank you to stampede for this useful post:

    andre_teprom (26th July 2013)

  13. #9
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Quote Originally Posted by stampede View Post
    Looks like you need to place the needed opencv dll files in folder where the app .exe is located, or in system PATH.
    Again, path to folder with qmake.exe shoud be in PATH env. variable.
    Here is what I did..
    I copied the opencv dll files to this location "C:\OpenCVProjects\MyQtConsoleProject-build-desktop\debug"
    I think I got the qmake setup in the PATH env. variable right. And this how I type the command "C:\OpenCVProjects\MyQtConsoleProject>qmake" no error output.
    But I when I compile the project I still have this message "exited with code -1073741511"

    Regards,
    lam-ang

  14. #10
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    Qt Code:
    1. Err.exe -1073741511:
    2. # for decimal -1073741511 / hex 0xc0000139 :
    3. STATUS_ENTRYPOINT_NOT_FOUND ntstatus.h
    4. # {Entry Point Not Found}
    5. # The procedure entry point %hs could not be located in the
    6. # dynamic link library %hs.
    To copy to clipboard, switch view to plain text mode 
    Are you sure you copy the same dll files that you link against ?

  15. The following user says thank you to stampede for this useful post:

    andre_teprom (26th July 2013)

  16. #11
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Quote Originally Posted by stampede View Post
    Qt Code:
    1. Err.exe -1073741511:
    2. # for decimal -1073741511 / hex 0xc0000139 :
    3. STATUS_ENTRYPOINT_NOT_FOUND ntstatus.h
    4. # {Entry Point Not Found}
    5. # The procedure entry point %hs could not be located in the
    6. # dynamic link library %hs.
    To copy to clipboard, switch view to plain text mode 
    Are you sure you copy the same dll files that you link against ?
    Please see the attachement if I have the correct dlls to the required folder.

    Thanks and regards,
    lam-ang
    Attached Images Attached Images
    Last edited by lam-ang; 17th July 2011 at 13:33.

  17. #12
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    Actually you need only two: libopencv_core230.dll and libopencv_highgui230.dll, place them in one folder with .exe file.
    Make sure you have test.jpg in project folder, or maybe instead of cv::imread("test.jpg"); try with cv::imread("C:/test.jpg");.
    Btw. what is your gcc version (type gcc -v ) ? OpenCV 2.3 needs gcc ver. 4.4 or higher.

  18. The following user says thank you to stampede for this useful post:

    andre_teprom (26th July 2013)

  19. #13
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi, I followed your suggestion,
    Qt Code:
    1. // main.cpp
    2. #include <opencv2/highgui/highgui.hpp>
    3. #include <opencv2/core/core.hpp>
    4.  
    5. int main(){
    6. cv::Mat image = cv::imread("C:/OpenCVProjects/MyQtConsoleProject/penguins.jpg");
    7. cv::namedWindow("My Image");
    8. cv::imshow("My Image", image);
    9. cv::waitKey(-1);
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Again thanks for your time, I appreciate it much.
    I think I still have some settings that I need to fix, because when I typed gcc -v I still have some issue...please see the attachement

    regards,
    lam-ang
    Attached Images Attached Images

  20. #14
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    Where did you get your mingw installation from ?

  21. #15
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    I got Qt 4.7.3, MinGW 4.4, please see my development environment..
    Attached Images Attached Images

  22. #16
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    I'm running out of ideas. Have you tried doing a clean build ? Is your operating system 32 bit ?
    Try using the system console:
    cd to project folder
    make clean
    qmake
    make release
    post the output.

  23. #17
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    I have windows 7 32bit..when I issue "make clean" to the system console I have some issue..probably this is causing the problem.
    Attached Images Attached Images

  24. #18
    Join Date
    Jul 2011
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt + OpenCV, simple example

    Hi!

    It seems I've found the thread what I need. I know the first step is the hardest one. I have to program a cross platform stereo camera based application, so the Qt + OpenCV should be an essential environment for my task.

    this thread is a good starting point, but i've stucked

    the first example has a reference to "C:/OpenCV2.2/build/bin" but the downloadable OpenCV2.2 has no binaries. I tried to compile it from console with the newest cmake and WinGW, but had no success, I've got only a flood of errors from cmake ...
    so i tried the "OpenCV2.3 superpack" example ... but when I try to run or debug the program under the Qt I always got this error message:
    Qt_CV_error.jpg
    but if i launch the exe file (with the requested OpenCV's DLLs in the same dir) it works perfectly ... i really don't understand why is this happening, and what should i do

    i don't want to lose the convenient of the Qt debugging functionality

    OpenCVTest.zip

    add. infos:
    gcc ver: 4.5.2
    Qt ver: 4.7.4
    win XP Prof SP3 32 bit


    Added after 10 minutes:


    yes!! I've found the solution ... in the Bulid settings I've changed the Tool chain to MinGw (x86 32bit) ... and that's it ... i can debug my app now ... cool
    Last edited by lokkoLori; 19th July 2011 at 14:31.

  25. The following user says thank you to lokkoLori for this useful post:

    andre_teprom (26th July 2013)

  26. #19
    Join Date
    Jul 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Qt + OpenCV, simple example

    Hi lokkoLori, I'm happy for you that you got your app running, I'm still stuck with my own setup. Probably I need to re install my opencv or perhaps my QTSDK..
    I notice when I type gcc -v in the command line I got an error..
    "sorry, \epoc32\gcc\bin\gcc.exe is not supoorted in this release"
    Any idea how to resolve this?
    regards,
    lam-ang

  27. #20
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt + OpenCV, simple example

    Whats in this C:\Symbian\ directory ? Looks like it contains gcc and make that is used instead of your mingw binaries. Can you remove this directory from PATH and try again ?

Similar Threads

  1. OpenCV + QT4
    By thereisnoknife in forum Qt Programming
    Replies: 6
    Last Post: 8th March 2013, 05:19
  2. opencv-qt-mac
    By ireneluis in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2010, 15:24
  3. Qt and OpenCV
    By malorie in forum Newbie
    Replies: 2
    Last Post: 7th March 2010, 14:57
  4. OpenCv & Qt4
    By switch in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2009, 15:12
  5. JAI vs. OpenCV vs. ITK
    By tpieciak in forum General Programming
    Replies: 0
    Last Post: 8th July 2009, 13:45

Tags for this Thread

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.