Code::Blocks + OpenCV setup...

1,023 views
Skip to first unread message

Charles Huber

unread,
May 14, 2011, 12:05:14 AM5/14/11
to ccckc
Code::Blocks + MingW
--------------------------
Download:
http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe

Install:
Defaults are OK.
Install to "c:\dev\CodeBlocks"

CMake
--------------------------
Download CMake:
http://www.cmake.org/files/v2.8/cmake-2.8.4-win32-x86.zip

Unzip Cmake to "C:\dev\CMake".
The "CMake" directory should have "bin", "doc", "man", and "share" in it.

OpenCV
--------------------------
Download OpenCV:
http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/OpenCV-2.2.0-win.zip/download

Unzip OpenCV to "C:\dev\OpenCV".
The "OpenCV" directory should have directories like "3rdparty",
"android", "modules", and "tests" in it, as well as some files,
including "README" and "CMakeLists.txt".


Building OpenCV
--------------------------
Building OpenCV:
Open up a cmd.exe window:
c:
cd c:\dev\OpenCV
mkdir build
cd build
c:\dev\CMake\bin\cmake-gui.exe ../

In the cmake-gui that pops up:
Hit "Configure"
Select "MinGW Makefiles" from the dropdown
Select "Specify native compilers" radiobutton
Hit "Next"
C compiler: C:/dev/CodeBlocks/MinGW/bin/gcc.exe
C++ compiler: C:/dev/CodeBlocks/MinGW/bin/g++.exe
Hit "Finish"
Should give you an error, hit "OK"
Main cmake-gui window, check "Advanced"
Edit CMAKE_MAKE_PROGRAM to be C:/dev/CodeBlocks/MinGW/bin/mingw32-make.exe
Hit "Configure" again
Shouldn't have any errors this time, but you should have a bunch more
Name/Value pairs in the center
Uncheck BUILD_NEW_PYTHON_SUPPORT
Uncheck BUILD_TESTS
Edit CMAKE_CONFIGURATION_TYPES to contain only "Release"
Hit "Configure" again
All the Name/Value pairs should be white now
Hit "Generate", shouldn't get any errors
Close the cmake-gui window

Back in your cmd.exe window (should still be in c:\dev\opencv\build):
c:\dev\CodeBlocks\MinGW\bin\mingw32-make.exe
*wait a while*
c:\dev\CodeBlocks\MinGW\bin\mingw32-make.exe install


Code::Blocks project
--------------------------
File->New->Project...
Select "Empty project"
Hit "Go"
Hit "Next"
Project title: opencv_test
Folder to create project in: C:\dev\projects\
Hit "Next"
Hit "Finish"
File->New->Empty File
Yes
Call it "main.cpp"
Hit OK

Right-click the "opencv_test" in the Projects sidebar
Select "Build options..."

Linker settings tab:
Link libraries box:
Add all files in C:\dev\OpenCV\build\lib
"No" to "Keep realative path"

Search directories tab:
Compiler:
C:\dev\OpenCV\build\include
C:\dev\OpenCV\build\include\opencv
C:\dev\OpenCV\build\include\opencv2
Linker:
C:\dev\OpenCV\build\lib

Copy all the DLLs in:
C:\dev\OpenCV\build\bin
to:
C:\dev\projects\opencv_test\bin\Debug
C:\dev\projects\opencv_test\bin\Release


OpenCV Hello World
--------------------------
Paste in this:

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int main(int argc, char** argv)
{
IplImage *img = cvLoadImage("image.bmp");
cvNamedWindow("Image:",1);
cvShowImage("Image:",img);

cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);

return 0;
}

Save file.

Make sure there's a "image.bmp" in C:\dev\projects\opencv_test

Build->Run, should display your image.

Good luck!
-Charles

Reply all
Reply to author
Forward
0 new messages