Sie sind auf Seite 1von 58

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? 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 after thought. 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-precisepangolin/
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 minGW
MinGW is 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:\MinGW
From 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 path


Navigate to Control Panel -> System -> Advanced System Settings
and 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::Blocks
Code::Blocks is an IDE (integrated development environment). Head to their website and
download the latest version (codeblocks-10.05setup.exe) http://www.codeblocks.org/downloads/binaries
Install it to the default location
When the installer finished click yes to run Code::Blocks
then go to Settings -> Compiler and Debugger
Under the Toolchain Executables select GNU GCC Compiler from the drop down and then
press AutoDetect
verify 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 OpenCV
OpenCV is a library of Computer Vision functions. Head to their website and download the
latest version (2.4.2 for Windows) http://opencv.org/downloads.html
Click 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 cmake
Open 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 the
rest 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 path
C:\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 path Make sure you restart
Code::Blocks before continuing if you have it open.
Step 6: Configuring Code::Blocks with OpenCV
Make 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
#include <opencv2/core/core.hpp>
2 #include <opencv2/highgui/highgui.hpp>
3
4 using namespace cv;
5
6 int main()
7 {
Mat image;// new blank image
8
image = cv::imread("test.png", 0);// read the file
9
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// create a
10window for display.
imshow( "Display window", image );// show our image inside it.
11
waitKey(0);// wait for a keystroke in the window
12
return 0;
13}
14
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
Facebook49

174 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.
Reply

2.

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.
Reply

Salah

1.

December 6, 2014 at 7:46 pm


i dont understood this step Help me plz
Reply

3.

Tobias
February 28, 2014 at 10:54 am
Thanks a lot but please add
mingw32-make install
mingw32-make clean
Reply

4.

mahmoud
April 8, 2014 at 1:32 am
thank you <3
Reply

5.

yldzmuhammed
May 12, 2014 at 2:11 pm
Hi.Thanks for this. I have some questions.
I dont understand your;

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. part.
What is that mean?I try open cmd and some command. Like gcc
C:\Opencv\opencv\build\x86\mingw but return error (
http://postimg.org/image/rnqpzazvt/ ).
I tried some combination. And i finish every step.When i compile your simple projects
code, it telling me missing dll file. It said that the libopencv_core243.dll file is
missing.
What should i do?
Reply

Jared

1.

June 14, 2014 at 2:36 am


I have the same problem (Codeblocks 13.12, OpenCV 2.4.9, Windows 7) I
have searched my computer for the file libopencv_core249.dll (my error is
with 249 not 243 but this is because of the version I think). the file
opencv_core249.dll DOES exist in my lib folder. it seems like somewhere in
the code there is a missing \ between lib and opencv when the dll file is
referenced. I looked around in some of the header files to see if I could figure
out where the reference was but nothing ( I didnt try very hard). sorry I dont
have a solution, I feel you pain. Any help with this issue?
Reply

1.

Arun Balajee Vasudevan


September 26, 2014 at 2:57 pm
If you have not resolved, I think problem is that C:/opencv/bin; which
contains the libopencv_core249.dll is not in the system path. I think
you add the above folder link to the path in the environment variable. I
also had the same problem

6.

yldzmuhammed
May 12, 2014 at 2:13 pm
Hi.Thanks for this. I have some questions.

I dont understand your;


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. part.
What is that mean?I try open cmd and some command. Like gcc
C:\Opencv\opencv\build\x86\mingw but return error (
http://postimg.org/image/rnqpzazvt/ ).
I tried some combination. And i finish every step.When i compile your simple projects
code, it telling me missing dll file. It said that the libopencv_core243.dll file is
missing.
What should i do?
Reply

kevinhughes27

1.

May 12, 2014 at 2:16 pm


I think you are either missing mingw or you didnt add it to the path. Plus you
need to type mingw32-make and not gcc
Reply

1.

Salah
December 6, 2014 at 8:22 pm
when i type mingw32-make i find this error :

Help me

2.

Erik
May 21, 2015 at 3:01 pm

Salah, I think you forgot to hit the generatebutton in Cmake. You


have only configured it but not generated it.

7.

arpit
May 13, 2014 at 8:10 pm
i didnt find C:\opencv\build\x86\mingw .
it only shows vc options
i would be glad if u could help
Reply

pallavi

1.

January 27, 2015 at 5:27 am


Make this folder. It is not already provided
Reply

8.

cristianbfristian
May 15, 2014 at 2:37 pm
Ive been having this error and I cant find a way to fix it:
The procedure entry point __gxx_personality_v0 could not be located in the dynamic
link library D:\opencv\build\x86\mingw\bin\libopencv_core249.dll.
Ive looked everywhere for a solution and I need this working soon. I hope you can
help me.
Reply

1.

kh_2011 (@Kh_Fadoua)
July 8, 2014 at 9:05 am
hi,
so pleaze, did you solve this problem ?! coz, actually, im facing it right now,
and i dont really know how to fix it :/
i would be more than grateful of you can answer me asap..
thank you in advance

Reply

9.

cristianbf
May 15, 2014 at 2:40 pm
I get this weird error and I cant find a way to fix it. I looks alike something that other
people had.
The procedure entry point __gxx_personality_v0 could not be located in the dynamic
link library D:\opencv\build\x86\mingw\bin\libopencv_core249.dll.
I dont know how to fix it and I need this working soon. I hope you can help me.
Reply

kevinhughes27

1.

May 15, 2014 at 3:33 pm


did you build your own binaries?
Reply

1.

cristianbf
May 15, 2014 at 3:36 pm
Yes. I followed every single step of this tutorial.

10.

kevinhughes27
May 15, 2014 at 3:39 pm
huh dont know what to tell you. Worked for me last time I did it (note that I dont
recommend doing this on windows for several reasons) Try rebuilding them?
Reply

1.

cristianbf
May 15, 2014 at 3:51 pm

huh I rebuilded and reinstalled everything. Thanks anyway.


Reply
11. Pingback: Code::Blocks OpenCv - 2 Sayfa
12. Pingback: Anonymous
13.

Chaithra Bharadwaj
June 6, 2014 at 6:01 am
Works perfectly.. Thanks a lot dude
Reply

14.

CMakeLists.txt
June 21, 2014 at 6:38 pm
CMake Error: The source directory C:/Libs/opencv does not appear to contain
CMakeLists.txt. When clicking configure. Maybe you should address this?
Reply

CMakeLists.txt

1.

June 21, 2014 at 10:15 pm


Fixed by changing the path to C:\Libs\opencv\sources
Reply

1.

Kumar Gaurav Jha


August 12, 2014 at 9:19 pm
Having the same problem; which path did you change brother?

15.

Chandrakanth
June 21, 2014 at 10:09 pm
I am getting the following during making mingw32-make.

[ 44% ] mingw32-make[2]: *** Access is denied.


. Stop.
mingw32-make[2]: *** Waiting for unfinished jobs
What could be the problem?
Thanks.
Reply

Krishna Harsha

1.

June 23, 2014 at 7:29 am


Try making it again.The same thing happened to my friend and it worked.
Incidentally his name is the same as yours. :D
Reply

16.

Pi_Co
July 14, 2014 at 3:04 am
So this is a two part question. The first part being how do you add the picture to the
top of the file directories in the sample script/ I tried just creating a folder for it and
just doing C:\test. The issues is with both approachs I get an unexpected error has
caused name_of_script.exe to stop working. I checked and found that I have
everything linked right so it leads me to the conculsion of it being an error in finding
the test.png photo.
Reply

kevinhughes27

1.

July 14, 2014 at 2:49 pm


If I recall correctly images go in the Code Blocks project root. To determine if
this is the issue or if it is indeed linking you can do 2 things first just put the
image all over your code blocks project directory and see if it works or write a
new hello world program that doesnt load from file but instead does
something like creates an identity matrix and prints it out. Good luck!
Reply

17.

viviwaiwai

July 27, 2014 at 7:15 pm


Thanks for the guidance. Program is compiled successfully but is having a message on
my windows
Process returned -1073741634 (0xC00000BE) execution time : 4.602 s
Press any key to continue.
Reply

18.

Hem
July 29, 2014 at 6:48 pm
hey.bro I followed exactly same steps you have mentioned.My codeblocks is
compiling open cv programs properly but It shows a entry point error missing libstdc+
+-6.dll missing.
And also I cant create project It shows project directory cant be created.
Reply soon Im really worried.
Reply

19.

Harrison Li
August 6, 2014 at 5:15 pm
Thanks a lot for the instruction. I just completed openCV 2.4.9 build using MinGW
64-bit, and tested it. I had some difficulty in the first attempt because of my
environment. Thanks again.
By the way, Im going to install Mint :-)
Best regards.
Reply

kevinhughes27

1.

August 6, 2014 at 6:04 pm


Excellent! Im sure youll love it!
Reply

20.

Kumar Gaurav Jha


August 12, 2014 at 8:38 pm
Having the same problem as asked by Arpit above I didnt find
C:\opencv\build\x86\mingw\lib, it only shows vc options While adding to the linker
in the last step.
Please guide. Thanks.
Reply

Harrison Li

1.

August 13, 2014 at 5:05 pm


You could just select a temporary target dir outside of openCV installation.
After you complete the build, there will be an install subdir in your target,
and if you build x64, it will contain x64\mingw\bin and x64\mingw\lib. Just
copy them to openCV installation dir.
Reply

1.

anang
September 2, 2014 at 8:57 am
Oh thanks very much sir, :)

2.

AlessioMTX
January 17, 2015 at 5:22 pm
C:\opencv\build\x86\mingw\lib is empty, I dont know why

21.

DVN
September 5, 2014 at 8:15 pm
I agree that developing on the Linux platform makes you code better problem is I
have a desktop and laptop that came with windows 8 preinstalled. this makes it very
difficult to install Linux alongside windows (i have tried and ended up having to reinstall the original image) does anyone have any tips? can it be done cleanly or do I
have to continue using virtual box?

Reply

kevinhughes27

1.

September 5, 2014 at 8:27 pm


Unfortunately I dont have any experience with Windows 8 at all. It should be
possible though and I imagine lots of people want this kind of setup so there
should be some info out there, have a google for it!
Reply

22.

shri
September 10, 2014 at 11:12 am
why here mingw lib file shows format of dll.a where we have .dll lib file.
could it be the reaason for error lib file missing libopencv_core243.dll
Reply

23.

yaman
September 16, 2014 at 1:25 pm
thanks for this tutorial,,,great work,,,helped me a lot,,,
but i want you to note this pointin step-4,
i got stuck here for two days,
using C:\opencv as the source directory gives an errorlocation c:\opencv does not seem to contain Cmakelist.txt file,
Instead of using C:\opencv as the source directory,using C:\opencv\sources did
worked fine.
Thanks again.
Reply

24.

nt
September 23, 2014 at 5:11 pm

I downloaded OpenCV from


http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.htm
l#windowssetpathandenviromentvariable
But I didnt find any mingw folder in the path : C:\opencv\build\x86. There are only 3
folders named vc10, vc11 & vc12. So, how do I proceed with the Step 5?
Reply

kevinhughes27

1.

September 23, 2014 at 5:14 pm


Read the update at the beginning of the tutorial OpenCV discontinued prebuilt binaries for MinGW you have to build your own now. The instructions
are all there though just keep reading
Reply

25.

mfh9498
September 24, 2014 at 1:49 pm
Hello, I got this message when running the Hello World program on Code Blocks:
the procedure entry point __gxx_personality_v0 could not be located in the dynamic
link libstdc++-6.dll > what does this mean? please advise. thank you.
Reply

26.

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 primaryexpression before ) token|
Help me out
Reply

27.

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-andtracking-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!
Reply

28.

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??
Reply

kevinhughes27

1.

October 10, 2014 at 6:58 pm


yes you can use mingw32 on x64 windows
Reply

29.

Laila Atty
November 18, 2014 at 7:55 pm
Thanks,
but I found a problem to find CMakeLists.txt
I found this Error
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.
how can I solve this ?
Reply

gabriel

1.

November 22, 2014 at 2:54 pm


change your source dir. to opencv\source
Reply

30.

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 :( ?
Reply

31. 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 !

Reply

33.

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

kevinhughes27

1.

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)
Reply

34.

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.
Reply

35. 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.
Reply

Saurabh

1.

April 3, 2015 at 7:55 am


hi,
You have written the command wrongly.
It should be mingw32-make
Reply

37.

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/mtgeh7nb7
Reply

Radnap

1.

March 31, 2015 at 2:46 pm


Sorry mistyped the link. The good one : http://postimg.org/image/mtqeh7nb7
Reply

Ladinde

1.

April 8, 2015 at 12:53 pm


If your problem isnt solve, i found an answer.
http://stackoverflow.com/questions/27663558/opencv-win8-1mingw32-source-code-error-tbbuttoninfo-was-not-declared-in-this
I 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 and
all seems fine with open cv and code blocks (OpenCV 3.0 GCC 4.8.1) but
trying 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!
Reply

kevinhughes27

1.

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.
Reply

Italian Job

2.

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 regards
Guido
Reply

1.

BH

May 29, 2015 at 7:34 pm


for highgui fix, go there:
http://code.opencv.org/issues/4087

39.

owadesign
April 30, 2015 at 6:33 pm
Hey,
This was exceptionally helpful, but unfortunately, I cannot seem to run the ming32make 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!
Reply

40.

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/4087
Many thanks!!
Reply

41.

Ishan a.
June 8, 2015 at 9:13 am
Hi
While running mingw32-make i am getting this error please help.
[ 79%] Generating core+CvException-jdoc.java, core+CvType-jdoc.java, core+Mat-jd
oc.java, core+MatOfByte-jdoc.java, core+MatOfDMatch-jdoc.java,
core+MatOfDouble-

jdoc.java, core+MatOfFloat-jdoc.java, core+MatOfFloat4-jdoc.java, core+MatOfFloa


t6-jdoc.java, core+MatOfInt-jdoc.java, core+MatOfInt4-jdoc.java, core+MatOfKeyPo
int-jdoc.java, core+MatOfPoint-jdoc.java, core+MatOfPoint2f-jdoc.java, core+MatO
fPoint3-jdoc.java, core+MatOfPoint3f-jdoc.java, core+MatOfRect-jdoc.java, core+P
oint-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+T
ermCriteria-jdoc.java, features2d+DMatch-jdoc.java, features2d+KeyPoint-jdoc.jav
a, gpu+DeviceInfo-jdoc.java, gpu+Gpu-jdoc.java, gpu+TargetArchs-jdoc.java, utils
+Converters-jdoc.java
modules\java\CMakeFiles\opencv_java.dir\build.make:4518: recipe for target modu
les/java/core+CvException-jdoc.java failed
mingw32-make[2]: *** [modules/java/core+CvException-jdoc.java] Error 1
CMakeFiles\Makefile2:5942: recipe for target modules/java/CMakeFiles/opencv_jav
a.dir/all failed
mingw32-make[1]: *** [modules/java/CMakeFiles/opencv_java.dir/all] Error 2
Makefile:135: recipe for target all failed
mingw32-make: *** [all] Error 2
I am unable resolve this please help.
Reply

Ishan a.

1.

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


asked Oct 9 '10 at
5:58

shareimprove this
question

edited Oct 9 '10 at


16:43

Ashish Yadav
71811122
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 I had this exact same problem a couple of weeks ago and couldn't find an answer
down vote anywhere ! After messing around with it, I found out exactly how to do it.
accepted

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.
shareimprove this
answer

How to link opencv in QtCreator and use


Qt library

This question must be duplicate many times, but it just doesn't work and sometimes
it still remains unanswered. Sources of information are mainly these
http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml
http://www.youtube.com/watch?v=dgcXYQijV6c
This 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 QtCreator
up vote
20 down
vote
favorite
16

1. 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_bin
5. 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.exe
6.1 source code: set the default dir for OpenCV;
C:\Programs\opencv24\opencv
6.2 binaries: set the opencv_bin dir; C:\Programs\copencv24\opencv_bin
6.3 click configure:
o

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++.exe
Field 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
o
o

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.exe
7. Go to the terminal (~command prompt), cd to the directory where are the
builds (opencv_bin) and type mingw32-make
8. When the process ends after a long time, type mingw32-make install
9. Add into Path variable the path to the QtCreator/bin
C:\Programs\Qt\Qt5.0.1\Tools\QtCreator\bin
Now 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 <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("img.JPG");
cvNamedWindow("hello");
cv::imshow("hello",mat);
cvWaitKey(0);
return 0;
}

c++ qt opencv qt-creator


asked Apr 8 '13 at 14:34
shareimprove this question

edited Jul 1 '13 at 15:49

Daniel Katz
3691417
I define LIBS here so that I use a directory opencv_bin2, because I rebuilt
opencv several times. Daniel Katz Apr 8 '13 at 22:43
My project cvImage is available on GitHub and demonstrates how to build a
2 cross-platform application with Qt/OpenCV. Check the .pro file. karlphillip
Apr 9 '13 at 2:28
I had to use "CMAKE_BUILD_TYPE = Release" rather than Debug as given
in here - your first source. inblueswithu Nov 17 '14 at 18:44
Anyways... I could not get this to working!! Not sure.. still pursuing it
inblueswithu Nov 19 '14 at 23:38
In CMake I keep getting this error: "Found unsuitable Qt version "" from
NOTFOUND, this code requires Qt 4.x" Birger Skogeng Pedersen Jan 30 at
10:39
show 1 more comment

1 Answer
active oldest votes
Finally I am starting to be happy. When adjusting this question I had to try all
ways, how to define LIBS. Listing them manually helped, at first I wrote them
somehow wrongly.
This is how it works finally:

up vote 5
down vote
accepted

LIBS += -LC:\\Programs\\opencv24\\opencv_bin2\\bin \
libopencv_core240d \
libopencv_highgui240d \
libopencv_imgproc240d \
libopencv_features2d240d \
libopencv_calib3d240d \

Btw if I've made any grammar mistakes, I am sorry for my english. :)


answered Apr 8 '13 at 22:37
shareimprove this answer

edited Apr 8 '13 at 22:57


Daniel Katz
3691417

I still don't know what was wrong with the original LIBS +=
"C:/Programs/opencv24/opencv_bin2/bin/*.dll" Daniel Katz Apr 8 '13 at
23:01
you need to add .libs because it contain information about functions inside
DLL, and this information is needed when building the project, so your exe
will run then check those information and then load needed DLL. Wajdy
Essam Apr 9 '13 at 8:20
Wajdy: Do you mean not an extention .lib or .libs, but rather any files within a
directory lib? Probably those in opencv_bin/lib and not opencv_bin/install/lib.
But when I simply change -LC:\\Programs\\opencv24\\opencv_bin2\\bin \ ...
to -LC:\\Programs\\opencv24\\opencv_bin2\\lib \ ... then it doesn't work. Are
you saying that the solution with \\bin \ ... is wrong? Daniel Katz Apr 9 '13
at 18:10
Wajdy: Even if I use the libs in install\lib it cannot find the .dll.a files though I
have a correct path set. Daniel Katz Apr 9 '13 at 18:25
@Wajdy: I've found out that if I use the other bin dir in install\bin, it works
too. But in both ways it doesn't work when I start the program by double click
on the .exe. - cannot find those dlls. Daniel Katz Apr 12 '13 at 18:54
Following this tutorial with OpenCV 2.46 and Qt Creator 2.7.2 was the only
way I was able to make this work. I don't have .NET installed. My .pro looks
like the one in this answer. DanyAlejandro Aug 3 '13 at 21:22
@daniel-katz I'm interested in this topic since I'm building an app with Qt and
OpenCV, and dynamic linking is necessary if one can't pay Qt commercial
fees. Can we get in contact? DanyAlejandro Aug 3 '13 at 21:38
@DanyAlejandro I'm sorry but I myself am not able to link anything

dynamically, I needed at least to make it work to do a homework. Though I'd


be still very glad if I knew how to do it. Daniel Katz Aug 13 '13 at 12:38
@DanielKatz, thank you so much for being helpful and informative. It
worked with me as a charm. CroCo Mar 30 '14 at 2:52
@DanielKatz, check out this link. It's the answer for your question.
stackoverflow.com/questions/12123479/ CroCo Mar 30 '14 at 2:56
add a comment

1. Playing with Images


1.1.2 Installing the OpenCV Library for Qt
The Qt SDK is probably the best tool to build cross-platform OpenCV applications. In
addition, it offers nice UI tools and a complete API. Finally, it comes with Qt Creator, a
friendly IDE for developing C++ projects. This recipe will show you, in details, how to install
Qt, compile the OpenCV library for it and finally run your first OpenCV application.
At the time of writing this recipe, the latest Qt version was 4.7.3 (Qt Creator 2.2.1). Current
version of OpenCV was 2.3.1 (August 2011). We will also use CMake which was at version
2.8.5. The installation has been done on Windows 7. Please refer to the OpenCV Cookbook
for more details.
1. The first step is obviously to download Qt. Simply run the installer with all default

option. Once installed, you can run Qt Creator.

2. Lets start by creating a simple Hello World application on the Windows console, just

to make sure everyting is working properly. Click on Create Project... and choose
Qt Console Application.

We will call our project myHelloWorld; place it in the location of your choice and
click Next.

We create a Desktop application.

A default project is then created.

This one does nothing except launching the concole. Click on the green arrow and you
will see it.

3. Lets now write a true Hello World application. Simply copy and paste the

following C++ code over the preceding one.


4.
5. #include <iostream>
6. int main() {
7.
std::cout << "Hello my world!";
8.
char var;
9.
std::cin >> var;
10.
return 1;
11. }

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.
12. 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.
13. 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.

14. 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.

15. 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.

16. 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!


17. Before we build our first OpenCV project, we need to add a few more folders to the

environment variable. First, you need to tell your system where to find the
OpenCV dlls. From our installation process, they are in C:\OpenCV2.3.1\install\bin.
Path

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

18. 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 <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
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 myFirstOpenCVProjectbuild-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!

Das könnte Ihnen auch gefallen