How do I install OpenCV 2.4 and compile my code with MinGW?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1. Installing OpenCV 2.4.3
First, get OpenCV 2.4.3 from sourceforge.net. Its a self-file-extracting so just double click the file to start installation. Install it in a directory, say
C:\.Wait until all files get extracted. It will create a new
directory
C:\opencvwhich contains OpenCV header files, libraries, code samples, etc.Now you need to add
C:\opencv\build\x86\mingw\bindirectory to your system PATH. This directory contains OpenCV DLLs which is required for running your code.Open Control Panel → System → Advanced system settings → Advanced Tab → Environment variables…
You will see a window like shown below:
On the System Variables section,
select Path (1), click Edit… (2), add
C:\opencv\build\x86\mingw\bin(3) then click Ok.This will completes the OpenCV 2.4.3 installation on your computer.
2. Installing MinGW compiler suite
I highly recommend you to use gcc (GNU Compiler Collection) for compiling your code. gcc is the compiler suite widely available in Linux systems and MinGW is the native port for Windows.
Download the MinGW installer from Sourceforge.net and double click to start installation. Just follow the wizard and select the directory to be installed, say
C:\MinGW.Select “C Compiler” and “C++ Compiler” to be installed.
The installer will download some packages from the internet so you have to wait for a while. After the installation finished, add
C:\MinGW\binto your system path using the steps described before.To test if your MinGW installation is success, open a command-line box and type:
gcc. If everything is ok, it will display this message:This completes the MinGW installation, now is the time to write your “Hello, World!” program.
3. Write a sample code
Open your text editor and type the code below and save the file to
loadimg.cpp.Put
lena.jpgor any image you like in the same directory with the file above. Open a command-line box and compile the code above by typing:If it compiles successfully, it will create an executable named
loadimg.exe.Type:
To execute the program. Result:
4. Where to go from here?
Now that your OpenCV environment is ready, what’s next?
C:\opencv\samples\cpp.