Use opencv in QT creator

Source: Internet
Author: User

Recently, opencv is used for image processing. Many people on the internet use Vs and opencv, but they do not like vs very much and want to use QT creator. I searched a lot of materials online and finally spent a day using opencv on QT creator.

Required Software: (1) Qt creator. My version is 4.8.5. This version is still installed when learning the QT creator of Yafei, there are online saying that the QT version is low, and the opencv version is high, it may be in the execution of the mingw32-make command will report an error. So in case of any problems

(2) opencv. My version is 2.3.0

(3) cmake http://www.cmake.org/cmake/resources/software.html

In addition, my computer's operating system is XP, 32-bit.

First install QT creator and cmake, which is quite simple. Install opencv and set the decompression path. Note the following before installing cmake: (1) the installation path cannot contain Chinese characters or spaces (2) Check and add all environment variables.

Add c: \ QT \ mingw \ bin to the system variable.

Cmake opencv, use cmake (http://www.cmake.org/) to generate the MAKEFILE file of opencv library, it should be noted that the folder in the extracted opencv storage path should not contain spaces or Chinese (My is E: \ opencv. Do not open cmake by using E: \ project \ opencv, E: \ open CV, and specify the source code location (that is, the location where opencv is extracted) and where the generated files are stored. In the configure dialog box, select mingw makefiles and specify native compilers.

The dialog box is used to specify the CIDR Block and c's compiler, and cuses gcc.exe. In the mingw/binsubdirectory under the qtsdk directory, the CIDR Block uses g1_cmd.exe:

Then configure again. If no error exists, select with_qt.

Again, configure prompts that the qmake executable file of QT cannot be found.

Manually specify the directory where qmake.exe is located

(Note that this image is copied by someone else on the Internet)

Configure again, generate if no error occurs.

 

1> run the CMD command to convert the directory to generate (my directory is F: \ opencv)

Cd f: \ opencv

2> run the CMD command to compile the file

> Mingw32-make

3> run the CMD command to compile install

> Mingw32-make install

 

 

Next, configure the opencv development environment of QT creator, copy the following three folders and put them in the same folder (only these three directories are required, and the remaining files and folders can be deleted, to save disk space)

 

(1) The build/include directory under the OpenCV-2.3.0 installation directory

(2) The bin directory after mingw compilation under the cmake target path

(3) The lib directory after mingw compilation under the cmake target path

Copy the structure of the three directories to the same directory. For example, I deleted other directories in the original cmake target directory and copied the include directory)

Add the bin directory to the system environment variable

Now, the opencv development environment under QT creator has been configured. Next, we will test whether the configuration is successful under QT creator.

Open QT creator, create an empty project, and add a CPP file named

Add the following opencv dependency file to the Pro file:

Export depath + = c: \ opencv \ include \ opencv \

C: \ opencv \ include \ opencv2 \

C: \ opencv \ include

 

Libs + = c: \ opencv \ Lib \ libopencv_calib3d230.dll.a \

C: \ opencv \ Lib \ libopencv_contrib230.dll.a \

C: \ opencv \ Lib \ libopencv_core230.dll.a \

C: \ opencv \ Lib \ libopencv_features2d230.dll.a \

C: \ opencv \ Lib \ libopencv_flann230.dll.a \

C: \ opencv \ Lib \ libopencv_gpu230.dll.a \

C: \ opencv \ Lib \ libopencv_highgui230.dll.a \

C: \ opencv \ Lib \ libopencv_imgproc230.dll.a \

C: \ opencv \ Lib \ libopencv_legacy230.dll.a \

C: \ opencv \ Lib \ libopencv_ml230.dll.a \

C: \ opencv \ Lib \ libopencv_objdetect230.dll.a \

C: \ opencv \ Lib \ libopencv_video230.dll.a

In this way, you can write your own program in the main function.

PS: The above are all pasted from various online tutorials. You may feel that there is a problem with the path.

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.