Construction of OPENCV+QT development environment under WIN7

Source: Internet
Author: User

1. Required Software tools:

(1) OpenCV Development Library,2.4.9 version, including source files (sources folder) and compiled files (build folder), but it's best to compile it yourself using CMake . otherwise easy error.

(2)Qt Creator, download the latest version on the official website, select the MinGW version number.

(3)CMake, download the latest version of the website.

2, install OpenCV. To extract the source files and post-compiled files to the folder:

F:\ProgramFiles\programme\openCV\openCV249

This includes two folders:build(post-compile file) and sources(source folder).

3, install Qt.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

(1) installation, you need to check the "MinGW4.8", the default is not checked.

(2) After installation, add the 3 environment variables of QT to "system environment variable" Path:

F:\ProgramFiles\programme\Qt\Qt560\Tools\mingw492_32\bin (the path of the GCC compiler, depending on your choice of installation folder);

F:\ProgramFiles\programme\Qt\Qt560\5.6\mingw49_32\bin (Increase the path.) is to avoid mingw config times wrong)

F:\ProgramFiles\programme\Qt\Qt560\Tools\mingw492_32\i686-w64-mingw32\lib (Increase the path is to avoid mingw config times wrong)

(3) Note that QT is completely installed, occupying a very large amount of disk space. Up to 5G, pay attention to arranging enough disk space to prevent the installation from failing due to insufficient space.

4, install CMake, and use CMake to control the OpenCV compilation process.

(1) Configure the compilation environment, "Configure", and then select "MinGW makefiles", the default option "usedefault native Compilers"( let MinGW find gcc and g+ through system environment variables + compiler. )

(2) Set the OpenCV"source file path" to be compiled and the resulting "target path". For example with.

(3)afterCMake compile, tick the option "with_opengl" and "WITH_QT" in the build list, the other items are best not to move.

(4) Click "Configure" button again. Red disappears.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

(5) Click "Generate" button to generate the makefile file. after success, the bottom will prompt generatingdone.

(a red warning appears.) can be ignored.

。。 )

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

(6) Open cmd. Go to the target path you just set

(F:\ProgramFiles\programme\openCV\buildBin), enter "mingw32-make" command to start compiling. This process is longer and requires about a minute or so.

(7) Run the Install command "mingw32-make install", this process is faster, about 1 to 2 minutes.

5. Configuring Qt Creator OpenCV Development Environment

(1) Set the folder (bin and lib folder) and OpenCV in the "target path" generatedin step 4 installation folder, under the " Build/include folder is placed under a folder. (Other folders in the target path are no longer required and can be deleted.) For example, the following. The folder

"F:\ProgramFiles\programme\openCV\openCV249\opencv\build\include" to the destination path folder "f:\ Programfiles\programme\opencv\buildbin"under.

(2) The destination path of the bin folder. Add to "system environment variable Path".

"F:\ProgramFiles\programme\openCV\buildBin\bin".

6 . At this point, the OpenCV development environment under Qt Creator has been configured well.

The following tests have been configured successfully under Qt Creator.

(1) Open Qt Creator. Create a new empty project, and then add a cpp file main.cpp.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

(2) add dependent files such as the following OpenCV to the Pro file

Includepath+=f:\programfiles\programme\opencv\selfbin\include\opencv\

F:\ProgramFiles\programme\openCV\selfBin\include\opencv2\

F:\ProgramFiles\programme\openCV\selfBin\include

Libs+=f:\programfiles\programme\opencv\selfbin\lib\libopencv_calib3d244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_contrib244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_core244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_features2d244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_flann244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_gpu244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_highgui244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_imgproc244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_legacy244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_ml244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_objdetect244.dll.a\

F:\ProgramFiles\programme\openCV\selfBin\lib\libopencv_video244.dll.a

In fact, there is a simple way. However, one drawback is that it is possible to include a large number of link libraries (this method is not successful.) )

Includepath+=f:\programfiles\programme\opencv\selfbin\include\opencv\

F:\ProgramFiles\programme\openCV\selfBin\include\opencv2\

F:\ProgramFiles\programme\openCV\selfBin\include

Libs+=f:\programfiles\programme\opencv\selfbin\lib

(3)the contents of the Main.cpp file are as follows:

#include "Cv.h"

#include "Cxcore.h"

#include "Highgui.h"

intMain (intargc,char*argv[])

{

// declaration iplimage pointer

iplimage*pimg;

// load Picture

pimg=cvloadimage ("e:/opencv/firstopencv/home.jpg",1);

// Create a form

Cvnamedwindow ("Image",1);

// display image

cvshowimage ("Image", PIMG);

// Wait for the button

Cvwaitkey (0);

// destroy form

Cvdestroywindow ("Image");

// release image

cvreleaseimage (&pimg);

return0;

}

(3.4) executes the program. You can see the picture display.

Construction of OPENCV+QT development environment under WIN7

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.