标签:
官方编译的OpenCV中只带了Python2的链接库,Python3的链接库需要自己特别编译,官方编译版下载地址:http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0-beta/
1. 解压opencv-3.0.0-beta.exe到D:/,安装cmake-2.8.12.2-win32-x86.exe,安装Python3.4(32位)且Python 需要安装 numpy
2. CMake设置:
1) cmake选择编译器为Visual Studio 10
2) Build类型中只需要将Build_opencv_python3勾上
3) 生成OpenCV的VS项目
3. 只需要编译bindings/opencv_python部分,但是中文Win7系统会得到如下错误:
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xff in position 0: illegal multibyte sequence error MSB6006: “cmd.exe” exited with code 1
需要修改D:\opencv\sources\modules\python\src2\hdr_parser.py
1) 第4行添加codecs库:import os, sys, re, string, codecs
2) 第737行:f = codecs.open(hname, "r", "utf-8")
4. 用Release模式重新编译bindings/opencv_python部分,将 “<BinaryOutput>\lib\release\cv2.pyd” 和 “<BinaryOutput>\bin\Release下所有的dll文件” 全部拷贝到C:\Python34\DLLs
5. 测试cv2模块:
import cv2 img = cv2.imread("D:\\acircles_pattern.png") cv2.namedWindow("Image") cv2.imshow("Image", img) cv2.waitKey (0) cv2.destroyAllWindows()
Reference:
1] http://stlt1sean.blogspot.sg/2013/05/64python-cv2pyd.html
2] http://www.crifan.com/summary_python_unicodedecode_error_possible_reasons_and_solutions/
3] http://www.360doc.com/content/14/0702/12/16740871_391447981.shtml
OpenCV 3.0.0-beta 编译支持Python3的链接库
标签:
原文地址:http://www.cnblogs.com/kind064100611/p/4354389.html