Configure opencv2.3.1 in QT creator and mingw

Source: Internet
Author: User

Some time ago I used QT and opencv to design an image processing framework for an experiment. I tried to configure and install opencv2.3.1 in OT creator and mingw. The configuration and compilation processes are as follows:

Note: The entire process is implemented on Windows XP.

1. Install cmake (my version is: cmake-2.8.7-win32-x86.exe), download link: http://www.cmake.org/cmake/resources/software.html

2, install ot creator (Version: qt-creator-win-opensource-1.3.0.exe), to QT official website have to download: http://qt.nokia.com

3, install QT Library (my version is: qt-win-opensource-4.6.4-mingw.exe), to the QT official website have to download: http://qt.nokia.com

Isn't mingw used to compile the opencv source code package? Why didn't mingw software be installed in the previous steps? The reason is this: when installing ot Creator will install a mingw; or interested friends can also download and install mingw, such as: mingw-get-inst-20111118.exe version, no matter what, with ot creator comes, or you can install mingw On Your Own (either of them ).

Note: before the next work, you must set some environment variables so that the following work can be completed smoothly.

Add the bin directory of cmake, the bin directory of QT creator, the bin directory of QT library, the bin directory of mingw, And the bin directory of opencv to the path variable in the environment variable, the mingw I use comes with QT creator (D: \ QT \ qtcreator-1.3.0 \ mingw \ bin), as follows:

Next we will use cmake to configure opencv:

A. Open the cmake software as follows:

Red 1 indicates the source code directory (D: \ Download \ opencv) after extracting opencv; Red 2 indicates the location of opencv (E: \ opencvmingw)

B. Click Configure, as shown below:

Select as marked, click Finish, and click Configure again. Then, click Generate to generate necessary files and makefiles under E: \ opencvmingw.

C. Now we have officially compiled opencv. You can compile opencv in QT 4.6.4 command prompt command mode to enter the directory configured by opencv, for example, my directory is E: \ opencvmingw, then input: mingw32-make on the command line, you can compile, but I don't, the prompt is missing file: libgmp-3.dll (but in D: \ QT \ qtcreator-1.3.0 \ mingw \ bin does exist in the libgmp-3.dll), this problem I do not know what is going on, then I was in WINXP built-in cmd command mode with mingw32-make success, if any netizens know what is wrong with the lack of libgmp-3.dll files, please let us know.

D, install opencv library, or in the above compiled directory, in command line mode input: mingw32-make install command will install opencv library, check whether an Install Folder is added to the compiled directory.

So far, compilation is all over. The following is an example of using opencv in QT Creator:

Configure the version of the QT Library: Open QT creator and select options under tools. The following is displayed:

Add qmake In the QT library.

Let's start our instance analysis and create a new project:

Some files are generated under c: \ opencvprojects: Main. cpp and myqtconsoleproject. Pro.

Modify main. cpp into our own Code as follows:

Modify myqtconsoleproject. pro file, add the opencv header file path and library file on the basis of the original file, as long as the original. add includepath and libs to the end of the Pro file. the Pro file is as follows:

If there is no error in compilation, We will generate our .exe file under the debugdirectory of the project, and select an image of the img.jpg file name under the DEBUG directory. Double-click the EXE file to display the following wonderful picture:

Well, I have finally seen some results. I hope the article will provide some reference for all netizens. At the same time, I have referenced some blogs from some netizens during my experiment, such as ghost! Thank you for your help and encouragement. At the same time, I hope you will put forward the shortcomings and omissions in the 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.