OPENCV Library under Windows QT compilation and use

Source: Internet
Author: User

    1. Prepare the required software

Mingw-gcc440_1
Qt-creator-win-opensource-2.5.0.exe
Qt-win-opensource-4.8.4-mingw.exe
Cmake-2.8.12.1-win32-x86.exe
Opencv-2.3.1-win-superpack.exe

    1. Software Installation

2.1 Install QT and configure the relevant environment variables.

2.2 Install CMake, the installation path is not allowed to have Chinese and white space.

2.3 Unzip OPENCV to C drive directory

    1. Compiling OPENCV

3.1 Open the CMake, specify the source location (that is, the OpenCV extracted from the place) and the place to store the generated files

As shown in the following:

Click the Configure button to pop up the dialog box and select Mingwmakefiles and specify native compilers

As shown in the following:

Click the Next button and the results are as follows:

Jump out of the dialog box to specify C + + and C compiler path, C with Gcc.exe, in the QT directory under the Mingw/bin subdirectory, C + + with G++.exe

Click Finish button to end back to the main screen, click the Configure button again, no error after selecting WITH_QT

As shown in the following:

Set the Cuda_toolkit_root_dir path to C:\Qt\mingw\bin

Click the Configure button again, then click Generate without error.

3.2 Compiling

A. cmd command go to generate directory (mine is as shown in D:\opencvMinGw)

CD D:\opencvMinGw

B. cmd command to compile the file

Mingw32-make

C. cmd command compile Install

Mingw32-make Install

As shown in the following:

3.3

After compiling and installing, there is an install directory under the directory where the generate generated, and all the results are compiled here, including Bin,lib and include, put the bin directory in the environment variable path, In fact, the entire install directory can be copied to a place to use, so that the contents of the OpenCV directory is completely deleted, the province occupies space. I've moved all the contents of the install into the OPENCVFORQT directory under the C drive.

    1. Sample test

Open the Qtcreator software to create a new console program, add an include in the project's. Pro file

And Lib as shown:

The main function code is as follows:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main ()
{
Cv::mat image = Cv::imread ("c:\\test.jpg");
Cv::namedwindow ("My Image");
Cv::imshow ("My image", image);
Cv::waitkey (5000);
return 1;
}

Run results

OPENCV Library under Windows QT compilation and use

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.