opencv install on windows with codeblocks

67
OpenCV Install on Windows With Code::Blocks and minGW ** Disclaimer ** Much to my dismay this tutorial is by far the most visited page on my website, why does this upset me? It upsets me because as glad as I am to see people using open source tools like OpenCV and MinGW rather than proprietary or commercial alternatives I feel strongly that developers should be using Linux not Windows for coding, especially for C++. Why should you use Linux? There’s a lot of reasons in my opinion but right now I am going to keep it simple. It will make you a better coder. period. Most people I know barely understand setting up their own C++ projects and linking to 3rd party libraries etc. and using Linux is the best way to see and learn how this works. I also personally recommend staying away from IDEs. Also Linux is quite often the first priority for developers of open source tools and windows support is sometimes an after thought. You’re obviously interested in open source or you wouldn’t be here – so I’m telling you to take the plunge, go all in, close this tab and grab an image of Ubuntu (or Mint if you want to be just like me :p ) and become enlightened! I’ll even go one step further and link some tutorials I use to install OpenCV on Linux and a link to my OpenCV project makefile. http://jayrambhia.wordpress.com/2012/06/20/install-opencv-2-4- in-ubuntu-12-04-precise-pangolin/ http://www.ozbotz.org/opencv-installation/ http://www.samontab.com/web/2011/06/installing-opencv-2-2-in- ubuntu-11-04/ https://gist.github.com/pickle27/5311609 ** Update ** I’ve been talking to the OpenCV devs about some of the issues people (and me) have been having with the latest pre-built

Upload: kosta-nikolic

Post on 09-Sep-2015

334 views

Category:

Documents


7 download

DESCRIPTION

EDEWWWE

TRANSCRIPT

OpenCV Install on Windows With Code::Blocks andminGW

** Disclaimer **Much to my dismay this tutorial is by far the most visited page on my website, why does this upset me? It upsets me because as glad as I am to see people using open source tools like OpenCV and MinGW rather than proprietary or commercial alternatives I feel strongly that developers should be using Linux not Windows for coding, especially for C++.

Why should you use Linux? Theres a lot of reasons in my opinion but right now I am going to keep it simple. It will make you a better coder. period. Most people I know barely understand setting up their own C++ projects and linking to 3rd party libraries etc. and using Linux is the best way to see and learn how this works. I also personally recommend staying away from IDEs.

Also Linux is quite often the first priority for developers of open source tools and windows support is sometimes an afterthought. Youre obviously interested in open source or you wouldnt be here so Im telling you to take the plunge, go all in, close this tab and grab an image of Ubuntu (or Mint if you want to be just like me :p ) and become enlightened!

Ill even go one step further and link some tutorials I use to install OpenCV on Linux and a link to my OpenCV project makefile.

http://jayrambhia.wordpress.com/2012/06/20/install-opencv-2-4-in-ubuntu-12-04-precise-pangolin/http://www.ozbotz.org/opencv-installation/http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/https://gist.github.com/pickle27/5311609** Update **Ive been talking to the OpenCV devs about some of the issues people (and me) have been having with the latest pre-built binaries, what you need to know is they are discontinuing pre-built binaries for MinGW.From now on you will have to build your own, I have included instructions for how to make your own binaries and its pretty straight forward. I still prefer MinGW to other compilers on windows (well actually I prefer Linux, see above) and I hope this tutorial will continue to be useful.

Step 1: Install minGWMinGWis a c/c++ compiler for windows, head to their website and download the latest version(right at the top where it says looking or the latest version?)http://sourceforge.net/projects/mingw/files/Install to the default location C:\MinGWFrom the options install mingw32-base and mingw32-gcc-g++, you can also install the other components if you wish, but all you need is the c++ compiler (g++).

Step 2: Add minGW to system pathNavigate toControl Panel -> System -> Advanced System Settingsand then:

Type a semi colon after the last entry in path and then paste your MinGW path (it should be C:\MinGW\bin if you chose the default location).

Afterwords open up a command prompt and type path to make sure it worked (you should see minGW somewhere in the print out, probably near or at the end).Programs will need to be restarted for this change to take effect.

Step 3: Install Code::BlocksCode::Blocksis an IDE (integrated development environment).Head to their websiteand download the latest version(codeblocks-10.05-setup.exe)http://www.codeblocks.org/downloads/binariesInstall it to the default location

When the installer finished click yes to run Code::Blocksthen go to Settings -> Compiler and DebuggerUnder the Toolchain Executables select GNU GCC Compiler from the drop down and then press AutoDetectverify that Code::Blocks has found MinGW

If you like now might be a good time to test your Code::Blocks and MinGW setup with a simple Hello World C++ program.

Step 4: Install OpenCVOpenCV is a library of Computer Vision functions.Head to their websiteand download the latest version(2.4.2 for Windows)http://opencv.org/downloads.htmlClick on the OpenCV-2.4.2.exe and choose C:\ as the extract directory

OpenCV is now installed but not configured with Code::Blocks

** Update **If this is your first time through the tutorial doing a clean install then skip this step first and see if the supplied pre-built binaries will work for you, if youve already tried and had issues or if you really want to build your own then continue with this section.

First youll need to download and install cmakeOpen cmake and select C:\opencv as the source directory and C:\opencv\build\x86\mingw as the directory to build the binaries (you could select any directory but choosing this one will overwrite the pre-built OpenCV binaries and then therest of the tutorial is the same. Click configure choose minGW makefiles wait and then click generate.

When cmake is done we need to open a command prompt in the build directory, so navigate to C:\opencv\build\x86\mingw then shift right click and choose open command window here then type mingw32-make. Mingw will now start compiling OpenCV, this will take a bit so feel free to do something else, when you come back type mingw32-make install and continue with the rest of the tutorial as is.

Step 5: Add OpenCV to the system pathC:\opencv\build\x86\mingw\bin (use the same process as above)

Note: Add x86 binaries regardless of your system type (32bit or 64bit) because minGW is 32bit.

Verify that both MinGW and OpenCV are in your system pathMake sure you restart Code::Blocks before continuing if you have it open.

Step 6: Configuring Code::Blocks with OpenCVMake a new Code::Blocks Project:

right click on your project and choose build options:

You can also change the global compiler settings from the menu bar at the top right.

Again Note we are using 32-bit binaries even though the system is 64-bit because the compiler is 32-bit.

Now run this simple OpenCV Hello World program to test that the install has worked.

1

2

3

4

5

6

7

8

9

10

11

12

13

14#include #include

using namespace cv;

int main(){Mat image;// new blank imageimage = cv::imread("test.png", 0);// read the filenamedWindow( "Display window", CV_WINDOW_AUTOSIZE );// create a window for display.imshow( "Display window", image );// show our image inside it.waitKey(0);// wait for a keystroke in the windowreturn 0;}

Download any image you want, rename it test.png or hard code its name and place it in the top of the project directory.

Note if you run your .exe from outside of code blocks the image needs to be in the same directory as the .exe.

As I mentioned earlier you can also configure OpenCV using the global compiler and debugger settings and the steps are the same, this means that every new project is ready to go with OpenCV.You can also choose file -> save project as template,This allows you to choose the option new from template and avoid the configuration each time.

Share this:

Twitter3 Facebook49174 comments

1. yash

February 24, 2014 at 9:47 am thanks a lot kevin!after dozens of websites n hours of waste, your guide came to rescue..

amazing set of guidelines!thanx again.

Reply2. French

February 25, 2014 at 6:03 pm Many thanks, it works without pain. All other method on the web seems forget mingw32-make and mingw32-make install steps.

Reply1. Salah

December 6, 2014 at 7:46 pm i dont understood this step Help me plz

Reply3. Tobias

February 28, 2014 at 10:54 am Thanks a lot but please add

mingw32-make installmingw32-make clean

Reply4. mahmoud

April 8, 2014 at 1:32 am thank you what does this mean? please advise. thank you.

Reply26. Dhiyagu

October 3, 2014 at 7:03 am Hi, Thanks for the post.

I tried it and it throws an error in operations.hpp like C:\opencv\build\include\opencv2\core\operations.hpp|3869|error: expected primary-expression before ) token|

Help me out

Reply27. Daniel

October 3, 2014 at 1:08 pm Hi,

Im trying to use Code Blocks and openCV with the tserial.h library.

Everything seems fine with open cv and code blocks, but Im not sure how to add the tserial.h library to the path.

Ive downloaded it frome here: http://www.tetraedre.com/advanced/serial/ and the code Im trying to use is here http://www.instructables.com/id/Face-detection-and-tracking-with-Arduino-and-OpenC/The error is: undefined reference to Tserial::Tserial()

If you have any clue of what the problem is, it would be wonderful!

Thanks for your help!

Reply28. Fizah Razif

October 10, 2014 at 3:48 pm hai thank for the tutorial

i already tried. but when i build the coding opencv error came out and im using 64 bit window. is it ok for me to used 32 bit mingw lib??

Reply1. kevinhughes27

October 10, 2014 at 6:58 pm yes you can use mingw32 on x64 windows

Reply29. Laila Atty

November 18, 2014 at 7:55 pm Thanks,but I found a problem to find CMakeLists.txtI found this ErrorCMake Error: The source directory C:/opencv does not appear to contain CMakeLists.txt.Specify help for usage, or press the help button on the CMake GUI.

how can I solve this ?

Reply1. gabriel

November 22, 2014 at 2:54 pm change your source dir. to opencv\source

Reply30. Gabriel

November 22, 2014 at 4:09 pm after cmake,I found that there is nothing generated in D:/Program Files/opencv/build/x86/mingw/bin & lib these two directory, even with adding

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

command to my cmakefile.txt.

Is anyone could help me figured out why :( ?

Reply31. Pingback: Fix Configure Error Zlib Not Installed Mingw Windows XP, Vista, 7, 8 [Solved]

32. Alexis

February 1, 2015 at 2:57 pm Thank you very much for this pretty easy tutorial I had unsuccessfully tried to install OpenCV a few months ago but this time it worked well.

I just want to point out an issue I ran into during compile-time :something like cannot find -lRunTmChk.I fixed it by disabling WITH_IPP in CMake, and recompiling.

All the best, from France !

Reply33. shweta

February 17, 2015 at 5:14 am tell me how to install opencv2 for python version 2.7.0 only

Reply1. kevinhughes27

February 17, 2015 at 8:37 pm just add the build flag for python (I dont remember it off the top of my head but youll see it in the cmake ui)

Reply34. Welch

February 19, 2015 at 8:50 pm I got this error when i try making the cmake generate:

CMake Error: The source directory C:/opencv does not appear to contain CMakeLists.txt.Specify help for usage, or press the help button on the CMake GUI.

Reply35. Pingback: CMake error with OpenCV in Windows 8.1 |

36. Nischal

March 21, 2015 at 4:39 am hi,when i type ming32-makei in cmd(at C:\opencv\build\x86\mingw) it shows not recognized as internal or external command,operable program or batch file.

i created mingw folder at C:\opencv\build\x86 as only vc folders were present. and then used Cmake.

Reply1. Saurabh

April 3, 2015 at 7:55 am hi,You have written the command wrongly.It should be mingw32-make

Reply37. Radnap

March 31, 2015 at 2:43 pm Hi,Thanks for the article ! While building binaries for MinGW i got an error when executing mingw-32-make.

http://postimage.org/image/mtgeh7nb7Reply1. Radnap

March 31, 2015 at 2:46 pm Sorry mistyped the link. The good one : http://postimg.org/image/mtqeh7nb7Reply1. Ladinde

April 8, 2015 at 12:53 pm If your problem isnt solve, i found an answer.

http://stackoverflow.com/questions/27663558/opencv-win8-1-mingw32-source-code-error-tbbuttoninfo-was-not-declared-in-thisI hope that can help someone.

38. Italian Job

April 13, 2015 at 10:33 pm I Kevin. Thanks a lot for your clean tutorial. I followed all steps andall seems fine with open cv and code blocks (OpenCV 3.0 GCC 4.8.1) buttrying to compile the easy sample i have this error:

F:/IPS_2/TESTCV/main.cpp:11: undefined reference to `cv::namedWindow(cv::String const&, int)F:/IPS_2/TESTCV/main.cpp:12: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)F:/IPS_2/TESTCV/main.cpp:13: undefined reference to `cv::waitKey(int)

Now : how is possible to have undefined reference to these functions and not to

imread() that is in same opencv .dll and declared in same header ?

Thanks in advance for your help and sorry for my poor english!

Reply1. kevinhughes27

April 14, 2015 at 12:40 am Im not sure its been a while now since Ive developed with opencv. I seem to remember there was a few dlls though so look around for some other ones.

Reply2. Italian Job

April 14, 2015 at 10:09 pm Thanks for the reply. I try with Opencv 2.4.11 and all works fine.It seems that CMakeList.txt of OpenCV 3.0.0 fails to create highgui.dll even if this option is selected in CMake.Really I dont know why! May be because 3.0.0 is a beta version and something not yet works. I will ask OpenCV and CMake guys about this problem and eventually i will report infos in this blog.Best regardsGuido

Reply1. BH

May 29, 2015 at 7:34 pm for highgui fix, go there:http://code.opencv.org/issues/408739. owadesign

April 30, 2015 at 6:33 pm Hey,

This was exceptionally helpful, but unfortunately, I cannot seem to run the ming32-make command successfully. Im getting this error:

C:\MinGW\bin\ar.exe: unable to rename ..\..\lib\libopencv_core_pch_dephelp.a';reason: File exists

What could I do to resolve this?

Thanks!

Reply40. BH

May 29, 2015 at 7:32 pm Hello, thanks a lot for your infos. builded opencv2.4.9 & mingW. all is ok,appart from one build error about this:TBBUTTONINFO was not declared in this scope during make.just fix it with commctrl.h modification , follow this link. to do the job.http://code.opencv.org/issues/4087Many thanks!!

Reply41. Ishan a.

June 8, 2015 at 9:13 am HiWhile running mingw32-make i am getting this error please help.

[ 79%] Generating core+CvException-jdoc.java, core+CvType-jdoc.java, core+Mat-jdoc.java, core+MatOfByte-jdoc.java, core+MatOfDMatch-jdoc.java, core+MatOfDouble-jdoc.java, core+MatOfFloat-jdoc.java, core+MatOfFloat4-jdoc.java, core+MatOfFloat6-jdoc.java, core+MatOfInt-jdoc.java, core+MatOfInt4-jdoc.java, core+MatOfKeyPoint-jdoc.java, core+MatOfPoint-jdoc.java, core+MatOfPoint2f-jdoc.java, core+MatOfPoint3-jdoc.java, core+MatOfPoint3f-jdoc.java, core+MatOfRect-jdoc.java, core+Point-jdoc.java, core+Point3-jdoc.java, core+Range-jdoc.java, core+Rect-jdoc.java, core+RotatedRect-jdoc.java, core+Scalar-jdoc.java, core+Size-jdoc.java, core+TermCriteria-jdoc.java, features2d+DMatch-jdoc.java, features2d+KeyPoint-jdoc.java, gpu+DeviceInfo-jdoc.java, gpu+Gpu-jdoc.java, gpu+TargetArchs-jdoc.java, utils+Converters-jdoc.javamodules\java\CMakeFiles\opencv_java.dir\build.make:4518: recipe for target modules/java/core+CvException-jdoc.java failedmingw32-make[2]: *** [modules/java/core+CvException-jdoc.java] Error 1CMakeFiles\Makefile2:5942: recipe for target modules/java/CMakeFiles/opencv_java.dir/all failedmingw32-make[1]: *** [modules/java/CMakeFiles/opencv_java.dir/all] Error 2Makefile:135: recipe for target all failedmingw32-make: *** [all] Error 2

I am unable resolve this please help.

Reply1. Ishan a.

June 8, 2015 at 9:52 am Resolved it turning java interface off.

installing opencv on windows(W32) to be used with code blocks

up vote 2 down vote favorite i am trying to use opencv library with code blocks(8.02).i have installed opencv2.1. when i include the headers and link the library its all fine.i have gone through http://opencv.willowgarage.com/wiki/CodeBlocks tutorial as well.but when i compile the project it reports no error or warning.it just says exit with status 1.

i want to know if anyone who has used opencv with code blocks and can please help me out of this situation.

thanks!!!

c++ configuration opencv codeblocks

share

HYPERLINK "http://stackoverflow.com/posts/3895879/edit" \o "" improve this questionedited Oct 9 '10 at 16:43

asked Oct 9 '10 at 5:58

Ashish Yadav71811122

1 there is a blog post opensourcecollection.blogspot.com/2011/04/ just in case you haven't seen yet Andrey May 20 '11 at 13:15 add a comment

1 Answer

active oldest votes

up vote 0 down vote accepted I had this exact same problem a couple of weeks ago and couldn't find an answer anywhere ! After messing around with it, I found out exactly how to do it.

1) Compile the library using Cmake. http://www.cmake.org/2) After your library is compiled you should have two different OpenCV libraries - a compiled one, and a non-compiled one.

3)In Code Blocks, click on Settings (In the File Menu). Under Settings, select Compiler and Debugger.

4)Select the Search Directories tab.Select the compiler tab under search directories. Click Add. Browse to your NON-COMPILED version of the library. In the non-compiled directory, select the include folder. Under the include folder, select OpenCV. Click OK

5)In codeblocks, select the linker tab, which is under the Search Directories tab.. Click on add and this time browse to your COMPILED version of the library. In the compiled directory, select the lib folder and click OK.

6) Go to the linker settings tab in codeblocks. Click Add. Browse to the COMPILED version of the library. In the compiled directory select lib. In the lib folder select all the libraries. Make sure to only select only the dynamic library files (.dylib extention)

7) Codeblocks is setup!

8) Run your project and it should work fine.

Feel free to ask for more help if you are still having problems.

share

HYPERLINK "http://stackoverflow.com/posts/7870060/edit" \o "" improve this answer

How to link opencv in QtCreator and use Qt library

up vote 20 down vote favorite

16This question must be duplicate many times, but it just doesn't work and sometimes it still remains unanswered. Sources of information are mainly thesehttp://www.laganiere.name/opencvCookbook/chap1s1_2.shtmlhttp://www.youtube.com/watch?v=dgcXYQijV6cThis is the summation of what I think one should/can do. (And now it works for me.) Hopefully I mentioned everything from the very beginning, the aim is to write a very clear tutorial.

Installation of OpenCV for QtCreator1. I have already MS Visual Studio 2010 Professional installed. (I have a free licence as a student) - I think this is not necessary, just a mention

2. Download: Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)2.1 Install: Warning, everything that Qt uses (e.g. OpenCV) must be in directories that don't contain white-spaces in their names. - i.e. "Program Files" is wrong. (But I don't want different program files to accumulate directly on C, so I've only made a folder "Programs" in which everything important is installed)

3. Download: cmake-2.8.10.2-win32-x86.exe - Install for all users (this can be in Program Files)

4. Download: OpenCV-2.4.0.exe, extract to: C:\Programs\opencv24 - it'll create a dir "opencv"; add another folder "opencv_bin". Now it looks like this:C:\Programs\opencv24\opencv*C:\Programs\opencv24\opencv_bin5. Set PATH environment variable, so that there be a link to MinGW compiler. e.g. C:\Programs\Qt\Qt5.0.1\Tools\MinGW\bin;6. Start cmake-gui.exe6.1 source code: set the default dir for OpenCV; C:\Programs\opencv24\opencv6.2 binaries: set the opencv_bin dir; C:\Programs\copencv24\opencv_bin6.3 click configure: Choose MinGW Makefiles and Specify native compilers, click next

Field C is for gcc.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/gcc.exe Field C++ is for g++.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/g++.exeField fortran can be empty, click finish

6.4 Many red lines will appear To the search field enter one by one: WITH_QT, WITH_TBB, WITH_IPP, WITH_CUDA, CMAKE_BUILD_TYPE

WITH_QT - must be selected.

WITH_TBB, WITH_IPP, WITH_CUDA - must be unselected

CMAKE_BUILD_TYPE - click and enter a text "Debug" (without quotes).

Clear the text from the Search field.

6.5 click configure and keep clicking configure until all red lines are gone, then click generate and close cmake-gui.exe7. Go to the terminal (~command prompt), cd to the directory where are the builds (opencv_bin) and type mingw32-make8. When the process ends after a long time, type mingw32-make install9. Add into Path variable the path to the QtCreator/bin C:\Programs\Qt\Qt5.0.1\Tools\QtCreator\binNow I have created a new console app in QtCreator.

//cvHello.pro

QT += core

QT -= gui

TARGET = cvHello

CONFIG += console

CONFIG -= app_bundle

TEMPLATE = app

INCLUDEPATH += C:/Programs/opencv24/opencv_bin2/install/include

LIBS += "C:/Programs/opencv24/opencv_bin2/bin/*.dll"

SOURCES += main.cpp

OTHER_FILES += \

img.JPG

And the main file:

//main.cpp

#include

#include "opencv2/core/core.hpp"

#include "opencv2/highgui/highgui.hpp"

#include "opencv/cv.h"

using namespace std;

int main()

{

cout var;

9. return 1;

10. }

And click again on the green arrow to run the new code.

If you obtain the result above, then everything is working well. Note that Qt automatically created a directory called myHelloWorld-build-desktop where it puts all the compiled and executable files. This way, the source code and the binary files does not get mixed together. This is very useful, if you use a version control software such as Subversion in which you submit only the source directory.

11. Let's now proceed to OpenCV installation. To download the OpenCV library, just go to the OpenCV official website at opencv.willowgarage.com. You'll find there the current release version in a downloadable zip file or in a Windows install. In the case of version 2.3.1, a superpack installer is available:

Run it and extract it to the directory of your choice:

Once this is done, you now have all OpenCV source files in the specified directory.

12. The next step is to compile the library for the compiler you want to use; here it will be the basic mingw/g++ compiler that Qt installed by default. Just before we do this, let's include the folder that contains the make command in our Path environment variable. Indeed, compiling the library will be done using this make utility command that Qt installed together with the compilers themselves. They are located in C:\QtSDK\mingw\bin. Goto to your Control Panel (from the Start menu) and to the System menu.

In the Advanced system settings menu, you select the Advanced tab.

Click on Environment Variables...

In the User variables box, look for the PATH variable. If it is there, click on Edit..., if not click on New... to create it. This variable contains all the folder Windows will look in when you type a command. By setting it in the user variables, this definition is available to you only. If you want it to be valid for all users of your system then define it in the System variables box.

13. To build the library from the source files, OpenCV uses CMake, a cross-platform and open source tool designed to build library packages. We need to install CMake. Go to cmake.org and download the Windows Win32 Installer.

14. Once CMake installed, you can start the gui-based application (cmake-gui)

In CMake, specify the directory containing the source code and the one that will contain the builds.

Click on Configure. This will create the output directory.

You then specify the compilers that will generate the project. In our case, they are the compilers of MinGW installed by default by Qt.

These are gcc and g++.

CMake now displays the different build options.

Select the build type, here Release. If you wish, at the end, you can repeat the same process with the Debug mode.

Since we want to use Qt, we also select the WITH_QT option

Once your options selected, you click on Configure again.

And you click on Generate to complete the installation.

15. Now that you have completed the installation, you are ready to compile the OpenCV library. Start the Windows cmd console and go to the directory where you installed your builds. Type mingw32-make

Building everything will take time...

Once this built completed, you type mingw32-make install

This last step will install the library and the include files in the install directory. Note that for clarity, you can rename this directory as release since you ask CMake to build a Release install

We are done with the installation! Congratulations!

16. Before we build our first OpenCV project, we need to add a few more folders to the Path environment variable. First, you need to tell your system where to find the OpenCV dlls. From our installation process, they are in C:\OpenCV-2.3.1\install\bin.

The Qt dlls are also required; you should find them at C:\QtSDK\QtCreator\bin

17. Our last step is to build a simple OpenCV project to make sure everything is working properly. Start Qt and create a new Qt Console Application project called here myFirstOpenCVProject. Goto to the projects menu and select the Release build configuration.

Our test program will simply open and display an image:

#include

#include

int main() {

// read an image

cv::Mat image= cv::imread("img.jpg");

// create image window named "My Image"

cv::namedWindow("My Image");

// show the image on window

cv::imshow("My Image", image);

// wait key for 5000 ms

cv::waitKey(5000);

return 1;

}

The project file must specify the OpenCV headers and libraries locations:

QT += core

QT -= gui

TARGET = myFirstOpenCVProject

CONFIG += console

CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

INCLUDEPATH += C:\\OpenCV-2.3.1\\install\\include

LIBS += -LC:\\OpenCV-2.3.1\\install\\lib \

-lopencv_core231.dll \

-lopencv_highgui231.dll \

-lopencv_imgproc231.dll \

-lopencv_features2d231.dll \

-lopencv_calib3d231.dll

You basically just have to add the last two definitions to the existing project:

Make sure you have an image called img.jpg in your myFirstOpenCVProject-build-desktop directory that is the default directory when you run your project from Qt.

and you should see the image displayed.

Wow! But this is just the beginning, you can do much more with OpenCV... Good luck!