jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

Build Qt and Configure Opencv with VS2015

已有 4627 次阅读 2018-1-20 07:13 |系统分类:科研笔记

It's been a long time since Qt and OpenCV frameworks were introduced to the opence source community, but it is not until recently peopole come to realize the benefits of combing them together, and such combination becomes increasingly popular among computer vision practitioners. This post is to walk you through the otherwise quite painful process for the installation and configurations step by step before you can dig into their wonderful applications.

------------------------------------------------------------------------------------------------------------------------------------------------

Building Qt from souce package

1. Prerequisites:

    Supported compiler: Visual Studio 2015 (wind64 command prompt) (see here: Compiling-a-c-program-from-visual-c-2015-command-prompt/)
    Perl version 5.24   [http://www.activestate.com/activeperl/]
    Python version 3.5.4 [http://www.activestate.com/activepython/]
    Ruby version 2.4.3 [http://rubyinstaller.org/]

2. Set environment variables for QTDIR, QMAKESPEC:

   QTDIR = C:\Qt\5.7.0\qtbase

   QMAKESPEC = win32-2015

   Add path: %QTDIR%\bin

   Reboot the computer to ensure the changes take effect!

3. Download QT soure package 5.7.0 (check: https://download.qt.io/official_releases/qt/5.7/5.7.0/single/  )

4. Launch Developer Command Prompt for VS2015

5. Environment setup for 64-bit: VC\vcvarsall amd64 (https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx)

6. Navigate to the Qt directory (here: C:\Qt\5.7.0\qtbase) and Type:

configure -static -debug-and-release -platform win32-msvc2015 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -qt-sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests (add any other feaetures you want, check: https://wiki.qt.io/Building_Qt_5_from_Git

7. When configure is complete, type: nmake [or jom (see: http://download.qt.io/official_releases/jom/ ), which will take much less time]

  Go grab a cup of coffee cause its going to take some time (about 4 hours) for the building process

8. Launch VS2015 and set the QT options

9. Building QT creator or simply use its exe installer(see: https://download.qt.io/development_releases/qtcreator/ and https://www.youtube.com/watch?v=zyG_gex9Ojs)

10. Set Qt bin path  and reboot the computer

-----------------------------------------------------------------------------------------------------------------------------------------------

Building Qt 5 for x64 platform contributed by Vincenzo Mercuri

Done! The Qt 5.0.0 libraries for x64 were compiled successfully with VS2010!
Here are the steps I’ve done (on Windows 7 Ultimate SP1 64bit):  first of all,
I must say that I had already installed VS2010 and Windows SDK 7.1 in the following order:

Visual Studio 2010
Windows SDK 7.1
Visual Studio 2010 SP1
Visual C++ 2010 SP1 Compiler Update for the Windows SDK 7.1
[this is required for building Qt5, here’s the link:
http://www.microsoft.com/en-us/download/details.aspx?id=4422%5D

After that, I installed:

-ActivePerl 5.16.1.1601 for x64
-Python 2.7.3 (for x64) through the installer at python.org
-ICU Libraries v50.1.1 for win64-msvc10
[these libraries provide Unicode and Globalization support and they
are required for building QtWebKit, you can download them here:
http://site.icu-project.org/download/50#TOC-ICU4C-Download%5D

I extracted the content of the folder “qt-everywhere-opensource-src-5.0.0”
[in qt-everywhere-opensource-src-5.0.0.tar.gz] to C:\Qt\5.0.0\
and made sure that the environment variables were properly set:

QTDIR=C:\Qt\5.0.0\qtbase
QMAKESPEC=win32-msvc2010

and added

%QTDIR%\bin;
C:\Qt\5.0.0\gnuwin32\bin;
C:\icu\bin64;
C:\Python27\DLLs;
C:\Python27

to PATH (“C:\Perl64\site\bin” and “C:\Perl64\bin” were already added
by the ActivePerl installation; however, make sure that they are properly set)

After making these changes I recommend to log off and re-log in,
this step shouldn’t be necessary in order to update the env variables,
but after many failures that’s what I did and it worked

Now, that’s the point where I lost much time. I couldn’t run the “configure.bat”
script in C:\Qt\5.0.0\, it just exited with an error message: configure.exe
is not a recognized command.. or something similar.. so, that’s my work around:
go into C:\Qt\5.0.0\qtbase, here you will find another “configure.bat”,
just open it with a text editor and comment out the 4th line:

if not exist %QTSRC%\.gitignore goto sconf

i.e. change it to:

::if not exist %QTSRC%\.gitignore goto sconf

at this point you can start the “Visual Studio x64 Win64 Command Prompt (2010)”
command prompt (in Start > Programs > Microsoft Visual Studio 2010 > Visual Studio Tools)

and then:

cd C:\Qt\5.0.0
configure -prefix %CD%\qtbase -release -opensource -icu -platform win32-msvc2010
C:\Qt\jom\jom.exe -jN

the “%CD%” placeholder stands for “current directory”, so you will find
your build in the subdirectory “qtbase”. This worked for both the x64
and x86 builds with *VS2010* (I used Python and Perl 32bit for the latter).
It DID NOT work for the Intel Compiler, the compilation process failed
after a few minutes. I’m working on it, though..

-----------------------------------------------------------------------------------------------------------------------------------------------

OpenCV Building and Configurations (v3.3 and above have included deep learning modules)

See Milania's Blog (https://milania.de/blog/Building_and_configuring_OpenCV_in_Visual_Studio_2015_with_source_code_mapping)  for building OpenCV with CMake)

In Opencv Building, make sure 'Build with QT' is selected (we are going to work QT with OpenCV), and finally you will see this screeshot :


Build opencv_world (https://stackoverflow.com/questions/38240573/opencv-world300d-dll-cannot-find-or-open-the-pdb-file);

Be careful of building with cuda, which may result in some error (https://stackoverflow.com/questions/42122634/building-opencv-3-cuda-errors), and you may also get a linker error pertaining to "python27_d.lib" or "python35_d.lib", as long as the error only pertain to Python it's ok.


#Configuration for working in VS (two approaches: local and global; refer to official document http://www.swarthmore.edu/NatSci/mzucker1/opencv-2.4.10-docs/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html )

1. Include & libraries: property page >>> VC++ directories >>> include directories >>> add 'C:\opencv-3.2\mybuild\install\include'; library directories >>> add 'C:\opencv-3.2\mybuild\install\x64\vc14\lib'

2. link to library lists: Linker >>> Input >>> Additional dependencies >>> add library lists as follows:

[Alternatively, use propery sheet (https://msdn.microsoft.com/en-us/library/669zx6zc.aspx#Property%20pages) to do the two steps]

#Lib File Lists (opencv3.2.0 in both release and debug modes):

debug:
opencv_cudabgsegm320d.lib
opencv_cudacodec320d.lib
opencv_cudafeatures2d320d.lib
opencv_cudafilters320d.lib
opencv_cudaimgproc320d.lib
opencv_cudalegacy320d.lib
opencv_cudaobjdetect320d.lib
opencv_cudaoptflow320d.lib
opencv_cudastereo320d.lib
opencv_cudawarping320d.lib
opencv_cudev320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_highgui320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_ml320d.lib
opencv_objdetect320d.lib
opencv_photo320d.lib
opencv_shape320d.lib
opencv_stitching320d.lib
opencv_superres320d.lib
opencv_ts320d.lib
opencv_video320d.lib
opencv_videoio320d.lib
opencv_videostab320d.lib
opencv_calib3d320d.lib
opencv_core320d.lib
opencv_cudaarithm320d.lib

Release:
opencv_cudacodec320.lib
opencv_cudafeatures2d320.lib
opencv_cudafilters320.lib
opencv_cudaimgproc320.lib
opencv_cudalegacy320.lib
opencv_cudaobjdetect320.lib
opencv_cudaoptflow320.lib
opencv_cudastereo320.lib
opencv_cudawarping320.lib
opencv_cudev320.lib
opencv_features2d320.lib
opencv_flann320.lib
opencv_highgui320.lib
opencv_imgcodecs320.lib
opencv_imgproc320.lib
opencv_ml320.lib
opencv_objdetect320.lib
opencv_photo320.lib
opencv_shape320.lib
opencv_stitching320.lib
opencv_superres320.lib
opencv_ts320.lib
opencv_video320.lib
opencv_videoio320.lib
opencv_videostab320.lib
opencv_calib3d320.lib
opencv_core320.lib
opencv_cudaarithm320.lib
opencv_cudabgsegm320.lib

#Configuration for QtCreator

CONFIG(debug,debug|release)

{
LIBS+=-LC:\\opencv-3.2.0\\mybuild\\x64\\vc14\\lib\
-lopencv_core320d\
-lopencv_highgui320d\
-lopencv_imgproc320d\
-lopencv_features2d320d
}
else
{
LIBS+=-LC:\\opencv-3.2.0\\mybuild\\x64\\vc14\\lib\
-lopencv_core320\
-lopencv_highgui320\
-lopencv_imgproc320\
-lopencv_features2d320
}

#A simple alternative is to create a pri file that is to be included in the pro file.


--------------------------------------------------------------------------------------------------------------

Simple test on OpenCV in Qt

------------------------------------------------------------------------------------------------------------------------------

Some building errors for OpenCV in QtCreator

realse and debug mode: https://stackoverflow.com/questions/20588440/include-path-for-adding-an-external-library-in-qt-creator/20589013#20589013

include path: http://doc.qt.io/archives/qt-4.8/qmake-variable-reference.html#includepath

include lib: http://doc.qt.io/archives/qt-4.8/qmake-variable-reference.html#libs


Sources:

https://www.youtube.com/watch?v=Aj41yY2Q1Bo

http://amin-ahmadi.com/2016/09/22/how-to-build-qt-5-7-statically-using-msvc14-microsoft-visual-studio-2015/

https://stackoverflow.com/questions/32996555/building-qt-for-msvc2015-and-get-working-projects

https://stackoverflow.com/questions/14932315/how-to-compile-qt-5-under-windows-or-linux-32-or-64-bit-static-or-dynamic-on-v

https://github.com/r52/op64/wiki/Quick-Guide-to-Compiling-Qt-for-op64

https://www.youtube.com/watch?v=tHwE_RTZPws

https://download.qt.io/official_releases/vsaddin/

For OpenCV:

http://blog.csdn.net/szfhy/article/details/50442602

https://www.youtube.com/watch?v=akAAAvGyLn0

https://github.com/MicrocontrollersAndMore/OpenCV_3_Windows_10_Installation_Tutorial

More great resouces:

https://stackoverflow.com/questions/15826893/building-qt5-with-visual-studio-2012-visual-studio-2013-and-integrating-with

http://zeroset.mnim.org/2015/07/15/building-visual-studio-x86-and-x64-binaries-with-cmake-nmake-and-qt-creator/

https://milania.de/blog/Building_and_configuring_OpenCV_in_Visual_Studio_2015_with_source_code_mapping

https://github.com/Milania1/TestProject_OpenCV

https://www.youtube.com/channel/UCDlX6TCvleveVo3063hAzhQ

https://github.com/PacktPublishing/Computer-Vision-with-OpenCV-3-and-Qt5

For building in codeblocks:

https://zahidhasan.github.io/2017-03-25-How-to-install-OpenCV-3.2-in-windows-10-using-MinGW-(64)-and-Codeblocks/

https://www.youtube.com/watch?v=G9IBIEDex18




https://blog.sciencenet.cn/blog-578676-1095829.html

上一篇:Revisit to Canny Edge Detector
下一篇:First Applications with QT
收藏 IP: 68.48.108.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 23:06

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部