# OpenCV_Qt **Repository Path**: zhangja0713/OpenCV_Qt ## Basic Information - **Project Name**: OpenCV_Qt - **Description**: Qt是一个1991年由Qt Company开发的跨平台C++图形用户界面应用程序开发框架;此处凭借QT 环境进行OpenCVの应用开发。 - **Primary Language**: C++ - **License**: 0BSD - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-06-30 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1. Environment - Windows10 64 - cmake-3.18.0 - Qt 5.12.9 - OpenCV 4.2.0 # 2. Software installed - [Qt 5.12.9 for Windows (3.7 GB) ](http://download.qt.io/official_releases/qt/5.12/5.12.9/qt-opensource-windows-x86-5.12.9.exe) - [cmake-3.18.0-rc2-win64-x64.msi](https://github.com/Kitware/CMake/releases/download/v3.18.0-rc2/cmake-3.18.0-rc2-win64-x64.msi) - [OpenCV – 4.2.0](https://sourceforge.net/projects/opencvlibrary/files/4.2.0/opencv-4.2.0-vc14_vc15.exe/download) # 3. Add Windows environment variables path: ``` D:\Qt\Qt5.12.9\5.12.9\mingw73_64\bin ① D:\Qt\Qt5.12.9\Tools\mingw730_64\bin ② ``` # 4. Cmake: 1. where is the source code=`D:/OpenCV4.2.0/opencv/sources` 2. where is build the binaries=`D:/OpenCV4.2.0/opencv/release` 3. Click Configure->MinGW Makefiles/Specify native compilers->C=`D:\Qt\Qt5.12.9\Tools\mingw730_64\bin\gcc` && C++= `D:\Qt\Qt5.12.9\Tools\mingw730_64\bin\g++` 4. waiting........... >............ Install to: C:/OpenCV4.2.0/release/install ———————————————————————— Configuring done 5. search: ``` with_OPENGL(√) with_OPENMP(√) ENABLE_PRECOMPILED_HEADERS(√) build_opencv_world(√) with_IPP() with_OPENCL_D3D11_NV() WITH_QT(√) ``` 6. **Configure** 7. waitting........ >Warning: `C:\OpenCV4.2.0\opencv\sources\.cache\ffmpeg `有三个文件需要外网(翻墙),故需要预先下载好放置此处即可 8. **Configure**->直到发现红色区域变白->点击**Generate** > ............ Install to: C:/OpenCV4.2.0/release/install > ———————————————————————— Configuring done Generating done # 5. Add Windows environment variables path: ``` D:\OpenCV4.2.0\opencv\release\bin ③ D:\Qt\Qt5.12.9\Tools\QtCreator\bin ④ ``` D:\OpenCV4.2.0\QT-Cmake\install\x64\mingw\bin # 6. 在release文件下:`shift+右击 `运行`Windows PowerShell`: ``` PS D:\OpenCV4.2.0\opencv\release> mingw32-make -j 8 //my CPU=8'Cores PS D:\OpenCV4.2.0\opencv\release> mingw32-make install ``` # 7. QT Created 1. QT->QT Widgets App->Desktop Qt MinGW 32bit 2. 右击项目->添加外部库->库文件:`C:\OpenCV4.2.0\release\install\x64\mingw\lib\libopencv_world420.dll.a` && 包含路径=`C:\OpenCV4.2.0\release\install\include` 为debug版本添加‘d’作为后缀(×); ``` win32:CONFIG(release, debug|release): LIBS += -LD:/OpenCV4.2.0/opencv/release/install/x64/mingw/lib/ -llibopencv_world420.dll else:win32:CONFIG(debug, debug|release): LIBS += -LD:/OpenCV4.2.0/opencv/release/install/x64/mingw/lib/ -llibopencv_world420.dll INCLUDEPATH += D:/OpenCV4.2.0/opencv/release/install/include DEPENDPATH += D:/OpenCV4.2.0/opencv/release/install/include ``` 3. Source/main.cpp: ``` #include using namespace std; using namespace cv; int main() { Mat image; char keyPress; cout<<"Welcome to Qt\n"; image=imread("C:/Users/Administrator/Pictures/lena.jpg",IMREAD_COLOR); imshow("Opnecv && QT",image); while (1) { keyPress=waitKey(); if(keyPress=='q') { destroyAllWindows(); break; } } return 0; } ``` # 8. QT release for exe in other Windows >准备工具: 1. QT5自带的windeployqt 2. [Engima Virtual Box](http://enigmaprotector.com/en/downloads.html) 1. 打开一个QT程序,以release方式运行一次 2. 在相应目录下会生成一个关于release的文件夹 3. 将文件下的`xxx.exe`程序拷贝出来,创建一个单独的文件夹`demo`中 4. 打开`Qt 5.12.9(MinGW 7.3.0 32-bit)`即`D:\Qt\Qt5.12.9\5.12.9\mingw73_32>` `D:\Qt\Qt5.12.9\5.12.9\mingw73_32>` 5. `cd`至`demo`文件下,并输入如下命令行:`windeployqt xxx.exe` 敲击回车。这一步操作是将所需的库文件全都拷贝到exe程序的当前文件: - `D:\Qt\Qt5.12.9\5.12.9\mingw73_32> cd /d C:\Users\Administrator\Documents\demoPack` - `C:\Users\Administrator\Documents\demoPack> windeployqt CV_Qtdemo.exe` ![packet](_v_images/20200630091619468_24292.png =459x) 6. 将`demo`文件下这一堆文件进行打包: - 打开运行**Enigma Virtual Box** - Enter input file name: Enter output file name: - 将包内所有文件后,直接拖入`VIRTUAL BOX Files `框内,选择【Files Options】->Compress File(√)压缩文件 - 点击Protect即可 7. Enjoy youself!!