原因: sift ,surf 已在美国申请专利。默认的opencv3.1版本并不包含sift ,surf 。sift,surf 及其他不稳定的算法函数都放在opencv额外模块里。该模块下载地址https://github.com/opencv/opencv_contrib。
安装方法网上已有,不再阐述。说下可能遇到的问题。
1. Cmake时,opencv_contrib的CMakeList会报错,报错的地方若不重要,可直接删除。
2. 用VS第一次生成,python3的cv2.pyd并未生成成功。重新用Cmake生成,并去掉python2的选项,只保留python3。再次用VS生成,报错
43>D:\opencv3.1\opencv_contrib-master\modules\aruco\src\aruco.cpp(1585): error C2660: “cv::calibrateCamera”: 函数不接受 12 个参数
43> dictionary.cpp
42> interfaces.cpp
42> motempl.cpp
42> optical_flow_io.cpp
43>D:\opencv3.1\opencv_contrib-master\modules\aruco\src\charuco.cpp(731): error C2660: “cv::calibrateCamera”: 函数不接受 12 个参数
Cmake 去除aruco模块
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(17): error C2039: “findDataFile”: 不是“cvtest”的成员
57> D:\opencv3.1\opencv\sources\modules\ts\include\opencv2/ts/ts_perf.hpp(609): note: 参见“cvtest”的声明
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(17): error C2660: “`anonymous-namespace'::findDataFile”: 函数不接受 2 个参数
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(21): error C2065: “Detection”: 未声明的标识符
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(21): error C2275: “std::string”: 将此类型用作表达式非法
57> D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(21): note: 参见“std::string”的声明
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(21): error C2062: 意外的类型“bool”
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(22): error C2143: 语法错误: 缺少“;”(在“{”的前面)
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(22): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
57>D:\opencv3.1\opencv_contrib-master\modules\text\test\test_detection.cpp(38): error C2504: “Detection”: 未定义基类
Cmake 去除text
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18318): error C2065: “vector_Blob”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18318): error C2146: 语法错误: 缺少“;”(在标识符“inputs”的前面)
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18318): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18319): error C2065: “vector_Blob”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18319): error C2146: 语法错误: 缺少“;”(在标识符“outputs”的前面)
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18319): error C2065: “outputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18323): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18325): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18325): error C2065: “outputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18326): error C2065: “outputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18333): error C2065: “vector_Blob”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18333): error C2146: 语法错误: 缺少“;”(在标识符“inputs”的前面)
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18333): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18338): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18340): error C2065: “inputs”: 未声明的标识符
89>D:\opencv3.1\Ericbuild\modules\python3\pyopencv_generated_types.h(18356): error C2065: “vector_Blob”: 未声明的标
Cmake 去除dnn
27>D:\opencv3.1\opencv_contrib-master\modules\ximgproc\src\fast_line_detector.cpp(121): error C3861: “CV_INSTRUMENT_REGION”: 找不到标识符
27>D:\opencv3.1\opencv_contrib-master\modules\ximgproc\src\fast_line_detector.cpp(140): error C3861: “CV_INSTRUMENT_REGION”: 找不到标识符
Cmake 去除ximgprocs
69>LINK : fatal error LNK1181: 无法打开输入文件“..\..\lib\Release\opencv_optflow310.lib”
3. 默认版本(不含contrib的cv2.pyd大小为2257KB),可以在cmd窗口用 : import cv2 , help(cv2.xfeatures2d) 来查看有没有安装成功。
VS生成relese解决方案的结果:
VS生成debug版本,错误:无法连接python3.5_d.lib
错误提示是: fatal error LNK1104: 无法打开文件“python26_d.lib” ,由于错误没有生成需要的文件。
错误的原因是系统安装有Python2.6,而默认的情况下Python是不提供python26_d.lib和python26_d.dll文件的。为了编译通过,需要在网上下载此二文件。CSDN的下载地址请点击这里。
将下载的lib文件置于X:/Program Files/Microsoft Visual Studio 9.0/VC/lib,dll文件置于X:/Program Files/Microsoft Visual Studio 9.0/VC/bin中,编译通过。
源码编译 python 生成 python35_d.lib
请参考连接http://blog.163.com/danshiming@126/blog/static/1094127482016525415131/