Configure MinGW + CodeBlocks + OpenCV2.3.1 in Windows 7

Source: Internet
Author: User

1. Download The mingw-get-inst-20111118: http://sourceforge.net/projects/mingw /;


2、double-click mingw-get-inst-20111118.exe. You can select the desired component by default;

 

3. Add MinGW environment variables: Select computer> right-click> select Properties> advanced system Settings> advanced> click environment variables> select PATH and click Edit, add C: \ MinGW \ bin to the environment variable, click OK, and enter gcc in cmd. If the prompt is fatal and no file is input, the installation is successful.

4. Download codeblocks-10.05mingw-setup: http://www.codeblocks.org/downloads/26;

5, double-click codeblocks-10.05mingw-setup, installation directory is best do not have Chinese or space, components according to their needs to choose, after the completion of the desktop will generate a CodeBlocks icon;

6. Double-click the CodeBlocks icon on the desktop and you will be prompted to select a default Compiler. Select gnu gcc Compiler and select Yes and associate Code in File associations :: blocks with C/C ++ file types;

7. Create a simple console application: File --> New --> Project... --> Projects, select Console application, click Go --> Next --> select C ++, and click Next --> Project title: projiect1; Folder to create project in: F: \ test \ codeblocks; Project filename: project1.white; Resulting filename: F: \ test \ codeblocks \ project1 \ project1.white; click Next --> default. Click Finish to generate a main by default. cpp file, compile and run it.

8. Download OpenCV2.3.1: http://www.opencv.org.cn/index.php/Download;

9. Download and decompress: OpenCV-2.3.1-win-superpack.exe to generate an opencv folder;

10. Download CMake: http://www.cmake.org/cmake/resources/software.html;

11. Install CMake;

12. Run CMake (cmake-gui) and enter the decompressed file path in where is the source code, such as D:/soft/OpenCV2.3.1, fill in the where to build the binaries file with the path to be stored during compilation, for example, D:/soft/OpenCV2.3.1/MinGW. This MinGW folder needs to be created by yourself;

13. Click Configure. In Specify the generator for this project, select MinGW Makefiles, select Specify native compilers, and click Next;

14. for Compilers: C, select the directory C:/MinGW/bin/gcc.exe; for C ++, select the directory C:/MinGw/bin/gw.20.cmd.exe and click Finish;

15. Select CMAKE_BUILD_TYPE and Debug;

16. Select BUILD_EXAMPLES;

17. Click Configure again;

18. Click Generate;

19, open the command prompt, enter the Directory D:/soft/OpenCV2.3.1/MinGW, enter the mingw32-make, press ENTER;

20, enter the mingw32-make install, press enter, Debug version compiled;

21. Return to the console application created in step 1, Project --> Build options... --> Select Debug, Linker settings --> Link libraries --> Add library: D: \ soft \ OpenCV2.3.1 \ MinGW \ install \ lib \ libopencv_calib3d231d.dll.a and others. dll. file a, click OK;

22. Select Search directories --> Compiler --> Add D: \ soft \ OpenCV2.3.1 \ MinGW \ install \ include;

23. Select Search directories --> Linker --> Add D: \ soft \ OpenCV2.3.1 \ MinGW \ install \ lib;

The Code is as follows:

# Include <iostream>

# Include <opencv2/opencv. hpp>

 

Using namespace std;

 

Int main ()

{

Cout <"Hello world! "<Endl;

 

IplImage * pImg;

 

PImg = cvLoadImage ("F: \ base.jpg", 2 | 4 );

 

CvNamedWindow ("Image", 1 );

CvShowImage ("Image", pImg );

 

CvWaitKey (0 );

 

CvDestroyWindow ("Image ");

CvReleaseImage (& pImg );

 

Return 0;

}

24. Test the corresponding dynamic library to the Debug folder, such as libopencv_core231d.dll and libopencv_highgui231d.dll. Run the command to display an image.

25. Just now, CMake only generates the Debug file. to generate the Release file, repeat steps 12 to 20. You must select CMAKE_BUILD_TYPE and select Release.


Author fengbingchun

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.