您的位置:首页 > 编程语言 > Python开发

Mac环境下python-opencv的安装

2017-11-09 07:43 447 查看
本文主要记录下Mac环境下的python-opencv的安装过程

环境准备

安装过程

测试代码

环境准备

python环境是必须的,如果没有安装可以参考python安装

默认应该是已经安装有的,可以输入命令确认: 

python


然后输出:

Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.


pip安装:

[pip简介],作者写的已经很详细,安装过程也很清楚。 可以测试命令是否正常:

pip


如果显示有各种命令的参数说明整个pip是正常的。

python-opencv安装过程

python-opencv依赖numpy、matplotlib,因此这两个包也是需要安装的,直接pip安装命令即可:

sudo pip install numpy
sudo pip install Matplotlib


然后直接安装python-opencv:

sudo pip install python-opencv


在这个过程遇到了一下问题:

DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling numpy-1.8.0rc1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/vp/9ptwx55s4gsggchycms4kjzw0000gn/T/pip-YtkWOq-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'


应该是版本不一致造成的,可以输入一下命令忽略然后安装:

sudo pip install numpy --ignore-installed six


然后可顺利安装

测试脚本

编写测试脚本testcv.py读取机器上的某一张图片,看能否显示:

#!/usr/bin/python# -*- coding: <encoding name> -*-

import cv2 as cv
img = cv.imread("/Users/cach/Downloads/chan.jpg")
cv.namedWindow("Image")
cv.imshow("Image",img)
cv.waitKey(0)
cv2.destroyAllWindows()


运行:python testcv.py,即刻显示图片:



至此整个python-opencv的安装和验证完成。

结语

后续将会更多的使用opencv来采集图像和识别,本次将作为基本的入门的知识。

http://blog.csdn.net/fancylovejava/article/details/39140373

http://blog.csdn.net/olanlanxiari/article/details/48086917

http://blog.csdn.net/id314846818/article/details/58624393

http://www.cnblogs.com/lclblack/p/6377710.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python mac opencv