-
2 Attachment(s)
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.
-
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.
Code:
TEMPLATE = app
DESTDIR = bin
TARGET = cvexample
DEPENDPATH += . src/cpp src/h src/ui
INCLUDEPATH += . src/h
UI_DIR = build
MOC_DIR = build
build_pass:CONFIG(debug, debug|release){
OBJECTS_DIR = build/debug
} else{
OBJECTS_DIR = build/release
}
win32 {
CV11_INCLUDE = C:/OpenCV2.3
CV11_LIB = C:/OpenCV2.3/lib
CV22_INCLUDE = C:/OpenCV2.3/modules
CV22_LIB = C:/OpenCV2.3/build/bin
} else{
CV11_INCLUDE = /usr/local/include/OpenCV
CV11_LIB = /usr/local/lib/OpenCV
CV22_INCLUDE = /usr/local/include/OpenCV2.3
CV22_LIB = /usr/local/lib/OpenCV2.3
}
contains(cv,2){
message(build with opencv 2)
DEFINES += OPEN_CV_22
INCLUDEPATH += $$CV22_INCLUDE/core/include/opencv2.3/core \
$$CV22_INCLUDE/highgui/include/opencv2.3/highgui \
$$CV22_INCLUDE/imgproc/include/opencv2.3/imgproc \
$$CV22_INCLUDE/core/include \
$$CV22_INCLUDE/imgproc/include
LIBS += -L$$CV22_LIB
LIBS += -lopencv_highgui220 -lopencv_core220 -lopencv_imgproc220
} else{
message(build with opencv 1.1)
DEFINES -= OPEN_CV_22
INCLUDEPATH += $$CV11_INCLUDE/cv/include $$CV11_INCLUDE/otherlibs/highgui $$CV11_INCLUDE/cxcore/include
LIBS += -L$$CV11_LIB
LIBS += -lcv -lhighgui -lcxcore
}
HEADERS += src/h/ImageCapture.h src/h/MainWidget.h
FORMS += src/ui/MainWidget.ui
SOURCES += src/cpp/ImageCapture.cpp src/cpp/MainWidget.cpp main.cpp
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
-
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 ?
-
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
-
1 Attachment(s)
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
-
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
Code:
#include <opencv2.3/core/core.hpp>
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:
Code:
// main.cpp
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
int main(){
cv::Mat image = cv::imread("test.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cv::waitKey(-1);
return 0;
}
Code:
// project.pro
TEMPLATE = app
QT -= gui
TARGET = SimpleCvApp
SOURCES += main.cpp
INCLUDEPATH += C:/OpenCV2.3/opencv/modules/core/include \
C:/OpenCV2.3/opencv/modules/highgui/include
# you can put the opencv .dll files where you want, this is where they are by default
# if you want to use different compiler or architecture, look for the libraries for your configuration in "OpenCV2.3/build" subfolder
LIBS += -L"C:/OpenCV2.3/build/x86/mingw/bin"
LIBS += -lopencv_core230 -lopencv_highgui230
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)
-
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:
Code:
Starting C:\OpenCVProjects\MyQtConsoleProject-build-desktop\debug\MyQtConsoleProject.exe...
C:\OpenCVProjects\MyQtConsoleProject-build-desktop\debug\MyQtConsoleProject.exe exited with code -1073741511
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
-
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.
Quote:
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.
-
Re: Qt + OpenCV, simple example
Quote:
Originally Posted by
stampede
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
-
Re: Qt + OpenCV, simple example
Code:
Err.exe -1073741511:
# for decimal -1073741511 / hex 0xc0000139 :
STATUS_ENTRYPOINT_NOT_FOUND ntstatus.h
# {Entry Point Not Found}
# The procedure entry point %hs could not be located in the
# dynamic link library %hs.
Are you sure you copy the same dll files that you link against ?
-
1 Attachment(s)
Re: Qt + OpenCV, simple example
Quote:
Originally Posted by
stampede
Code:
Err.exe -1073741511:
# for decimal -1073741511 / hex 0xc0000139 :
STATUS_ENTRYPOINT_NOT_FOUND ntstatus.h
# {Entry Point Not Found}
# The procedure entry point %hs could not be located in the
# dynamic link library %hs.
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
-
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.
-
1 Attachment(s)
Re: Qt + OpenCV, simple example
Hi, I followed your suggestion,
Code:
// main.cpp
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
int main(){
cv::Mat image = cv::imread("C:/OpenCVProjects/MyQtConsoleProject/penguins.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cv::waitKey(-1);
return 0;
}
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
-
Re: Qt + OpenCV, simple example
Where did you get your mingw installation from ?
-
1 Attachment(s)
Re: Qt + OpenCV, simple example
I got Qt 4.7.3, MinGW 4.4, please see my development environment..
-
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.
-
1 Attachment(s)
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.
-
2 Attachment(s)
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:
Attachment 6687
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
Attachment 6688
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 :)
-
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
-
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 ?