python学习_安装opencv

Posted Leslie X徐

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python学习_安装opencv相关的知识,希望对你有一定的参考价值。

opencv安装

安装

pip3 install --upgrade pip

pip3 install opencv-python

若发现import cv2出现
问题1:

ImportError: libcblas.so.3: cannot open shared object file: No such file or directory

解决

sudo apt-get install libatlas-base-dev

问题2:

ImportError: numpy.core.multiarray failed to import

解决

pip3 install -U numpy

如果安装出错想删除安装包

>>pip cache dir
/home/pi/.cache/pip

找到缓存文件并删除

测试文件

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main(args):
	import cv2
	import numpy
	
	mat = numpy.zeros((300,400),dtype = numpy.uint8)
	
	mat = cv2.cvtColor(mat,cv2.COLOR_GRAY2BGR)
	cv2.imshow('main',mat)
	cv2.waitKey()
	
	return 0

if __name__ == '__main__':
	import sys
	sys.exit(main(sys.argv))

以上是关于python学习_安装opencv的主要内容,如果未能解决你的问题,请参考以下文章