Build OpenCV 3.1 from source files on Windows
来源:互联网 发布:数据库unique 编辑:程序博客网 时间:2024/05/01 04:03
=== 15/12/2016 更 ===
Now EVERYTHING is working!! It is real this time :)
=== 16/11/2016 小更 ===
Re-build OpenCV 3.1.0 with Tesseract support!! (OK, it’s not - just text detection is running. if try recognition nothing happened. But still built!!)
- OpenCV CMakeLists.txt will try to detect dependent libraries automatically
- For opencv_contrib, they are checked by:
# Extra OpenCV targets: uninstall, package_source, perf, etc.
include(cmake/OpenCVExtraTargets.cmake)- OpenCVExtraTargets.cmake
- For tesseract:
opencv_contrib\modules\text\FindTesseract.cmake
- If no tesseract detected or configured manually, opencv_text can still build for Scene Text Detection but NO Scene Text Recognition apparently.
=== 15/11/2016 小更 ===
errors on build opencv with cvv module and qt5 #577 The build was absolutly clean. Configured by gui cmake 3.3.2. While configuring BUILD_DOCS, BUILD_PERF_TESTS and BUILD_TESTS entry was unchecked. WITH_QT was checked and OPENCV_EXTRA_MODULES_PATH specified. The rest remained in the default state. Build has been made through VS2013 x86 command prompt by command:
msbuild OpenCV.sln /flp:logfile=msvc2013_cvv.log /clp:ErrorsOnly > msvc2013_cvv_err.log
=== 更新 11/11/2016 ===
编译OpenCV 3.1.0 后,在新建的工程中用CMake 是怎么能自动找到新的OpenCV版本的???
=== 再更新 14/11/2016 ===
背景
也许还是绕不开Windows 的。
区别
OpenCV 3.1有预编译版本可以下载,只要添加一个opencv_world310.lib 即可使用。但是很多有用的功能都被转移到 一个单独的 opencv_contrib 库里面,需要额外编译。但是这个库又不独立,需要在编译 OpenCV 的时候把开关打开
操作
The official tutorial is way out of date.
Installation in Windows
This one is more recent and using the same VS 2013 64 bit but on Windows 7.
问题及解决
CUDA
一开始准备build 32 bit,但是机器上安装的CUDA 7.0 下Win32 的 cuxxx.lib 库都没有。
改成64 bit 就直接通过。以后再找原因
opencv_contrib
Just turn on the flag in CMake,
cmake -DOPENCV_EXTRA_MODULES_PATH=/modules
Building now. Take absolutely ages… Building CUDA alone is about ~3 hours!!
However CUDA it’s much faster, finished at 14:50!!!
Scene Text Detection
Just worked on Windows 10 now!
Except for some reason, er_filter2->run(channels[c], regions[c]);
not working
Maybe initialisation wrong Ptr<ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("trained_classifierNM2.xml"), 0.5);
Solution Just comment out.
后续
今天(01/11/2016)继续编译 OpenCV Debug 版本。一共153个子项目,10:05am 开始。
Files like
$OpenCV\modules\core\include\oepncv2\core\base.hpp
$OpenCV\modules\core\include\opencv2\core\cuda.hpp
$OpenCV\
$OpenCV\
are taking particularly looong time to compile.
Finished around 1300 so about 3 hours in total!
后续Problem
Error 1 error LNK1104: cannot open file ‘python35_d.lib’
C:\Development\opencv\build\modules\python3\LINK opencv_python3
Python bindings linker error during DEBUG build “python35_d.lib” #7395
You just need to install Python "_d.lib". Modern Python Windows installer allows to select installation of debug components (check message 241155 by your link). Or your need to build Python debug library from sources.
Using Python 3.3 in C++ ‘python33_d.lib’ not found
Simple solution from the python bug tracker:
#ifdef _DEBUG
#undef _DEBUG
#include <python.h>
#define _DEBUG
#else
#include <python.h>
#endif
To build debug version of Python from source:
In the event that you need a debug version (as I do for work), it is possible to build the library yourself:
LNK1104: cannot open file ‘python34_d.lib’
the fix is to change the hardcoded DEFAULTLIB on line 325 of pyconfig.h to use the release lib
Useful trick
extract lines from canny edge detection
- Setting the Canny thresholds with the meanStdDev
(mu, sigma) = cv2.meanStdDev(stairs8u)edges = cv2.Canny(stairs8u, mu - sigma, mu + sigma)lines = cv2.HoughLines(edges, 1, pi / 180, 70)
- nice little algo maybe worth trying in future
Steps:
- detect edges with probabilistic houghman.
- build a 2d histogram of edges based on rho and theta.
- merge almost colinear line segments. in each bin
- remove short lines
- due to discritization problem of histogram, lines almost on the boundary of a bin but could be merged with a line from the neighbor bin is then migrated to the other bin and lines are merg
“自动”检测OpenCV ?!!
疑惑在于:
- OpenCV 3.1.0是编译了,但并没有所谓的安装程序。也没有拷贝到所谓系统目录,C:\Windows, Program Files (x86)等
- CMakeLists.txt 使用
FIND_PACKAGE(OpenCV REQUIRED)
, 但是并不通过CMAKE_MODULE_PATH
指定Config.cmake
的位置,居然能一直找到!!
猜想:
- 查找了2个小时! 目前唯一的发现是打开OpenCV.sln,在
CMakeTargets-->INSTALL-->Properties-->Build Events-->Post-Build Event
下,有一些脚本,可能是唯一关联OpenCV 和 CMake的地方
setlocal"C:\Program Files (x86)\CMake2\bin\cmake.exe" -DBUILD_TYPE=$(Configuration) -P cmake_install.cmakeif %errorlevel% neq 0 goto :cmEnd:cmEndendlocal & call :cmErrorLevel %errorlevel% & goto :cmDone:cmErrorLevelexit /b %1:cmDoneif %errorlevel% neq 0 goto :VCEnd
=== 再更新 ===
答案!!!
今天(14/11/2016)有花了一个小时,终于找到了隐藏的指示信息!!
- Windows 注册表 (Registry)!!
- 个人一直很讨厌注册表,因为有太多细节可以被隐藏在注册表里,而注册表的功能又太强大!
- 在我机器上的位置和下面文章中说的就不一致—又一个例子
HKEY_CURRENT_USER\SOFTWARE\Kitware\CMakeSetup\Settings\StartPath\
下的WhereBuild#
Key, 其中# 为递增整数。每次用CMake Build一个项目,就会自动增加。- 另外,所有的变量设置都没有效果(see the end of this blog),也许我用错了语法。。。
set(NO_CMAKE_PACKAGE_REGISTRY ON)set(NO_CMAKE_SYSTEM_PACKAGE_REGISTRY ON)SET(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY TRUE)SET(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY TRUE)
> reg query HKCU\Software\Kitware\CMake\Packages\MyPackage
What is the default search path for find_package in windows using cmake?
The CMake manual fully specifies the rather complicated search order for the different find_* commands. Unfortunately, since Windows lacks a default directory structure à la /usr/local/lib, it is hard to come up with reasonable defaults here.
For find_package CMake offers a special mechanism on Windows called the package registry. CMake maintains a list of package information in the Windows registry under HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\. Packages build from source can register there using the export command. Other projects build later on the same machine will then be able to find that package without additional configuration. This is quite powerful if you need to build a lot of interdependent projects from source on the same machine.
CMake Manual for find_package
5. Search paths stored in the CMake User Package Registry. This can be skipped if NO_CMAKE_PACKAGE_REGISTRY is passed or by setting the CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY to TRUE. See the cmake-packages(7) manual for details on the user package registry.
7. Search paths stored in the CMake System Package Registry. This can be skipped if NO_CMAKE_SYSTEM_PACKAGE_REGISTRY is passed or by setting the CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY to TRUE. See the cmake-packages(7) manual for details on the system package registry.
Package Registry under cmake-packages(7)
CMake provides two central locations to register packages that have been built or installed anywhere on a system:
- User Package Registry
- System Package Registry
Disabling the Package Registry
In some cases using the Package Registries is not desirable. CMake allows to disable them using the following variables:
- CMAKE_EXPORT_NO_PACKAGE_REGISTRY disables the export(PACKAGE) command.
- CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY disables the User Package Registry in all the find_package() calls.
- CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY disables the System Package Registry in all the find_package() calls.
- Build OpenCV 3.1 from source files on Windows
- Build OpenCV from source with CUDA support
- Installing MySQL from Source on Windows
- build opencv by mingw & cmake on windows
- build ubuntu from source
- build tensorflow from source
- XML Comments Let You Build Documentation Directly From Your Visual Studio .NET Source Files
- Build OpenSolaris from source code
- Build distcc from source code
- gpsd build build from source (CentOS 6.5)
- How To Build xfstools, xfsprogs And xfsdump From Source On Ubuntu
- Build Kerberos on windows
- Build WebKit On Windows
- Build CSipSimple on Windows
- Build OpenJDK8 on Windows
- build hadoop2.0.3 alpha from source
- Qt for IOS:build from source
- Implement Lock files on Windows
- 剑指offer-二叉搜索树的后序遍历序列
- Golden Dream-11月
- HDU-5952 Counting Cliques(16年ICPC沈阳赛区)(暴力DFS)
- iOS 导航栏标题文字颜色渐变
- HDU-1301-Jungle Roads
- Build OpenCV 3.1 from source files on Windows
- python数据类型详解
- HDU 1106 排序(简单分类模拟)
- LeetCode 100. Same Tree
- Mac下使用mysql
- 爬动的蠕虫
- BSOJ 3022 又一类数字三角形--根据数据范围的优化+背包思想递推/搜索
- Atitit 编程语言原理与概论attilax总结 三大书籍总结
- TCP迭代服务器