3

一看就会的 Anaconda 搭建 OpenCV for Python 环境(全平台通用) - AhtelekB

 1 year ago
source link: https://www.cnblogs.com/AhtelekB/p/18e12ea3.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

前言#

在学习 OpenCV 的时候,需要搭建 OpenCV 的环境并安装一些库,本文就准备了 OpenCV for Python,换而言之就是 OpenCV 的 python 的 API 接口。它拥有 OpenCV C++ API 的功能,同时也拥有 Python 语言的特性。

视频教程#

准备工作#

安装 Anaconda 配置好国内镜像源

Windows 安装

Ubuntu 安装

版本信息#

Python 版本 3.6
OpenCV 版本 3.4.1.15
OpenCV 扩展包版本 3.4.1.15
dlib 版本 19.6.1

开始搭建#

Anaconda 创建 Python 虚拟环境

conda create -n OpenCV3.6 python=3.6    # 通过 anaconda 创建虚拟环境

# 点 y 即可

2977530-20230123193329504-220514205.png

激活虚拟环境

activate OpenCV3.6 # 激活虚拟环境

2977530-20230123193536051-2015655394.png

安装所需资源库

pip install opencv-python==3.4.1.15
pip install opencv-contrib-python==3.4.1.15
pip install dlib==19.6.1
pip install numpy
pip install matplotlib

2977530-20230123193644746-1149243346.png

检查是否成功
显示 3.4.1 就没问题了

# 检查是否成功

python
import cv2
cv2.__version__

2977530-20230123193854750-1017863397.png

程序测试#

# 导入cv模块
import cv2

# 读取图像,支持 bmp、jpg、png、tiff 等常用格式
img = cv2.imread('img\cat.jpg')

# 创建窗口并显示图像
cv2.imshow('image', img)
cv2.waitKey(0)

# 释放窗口
cv2.destroyAllWindows()

展示运行结果

参考资料#


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK