1、安装python
网址:
官网:Welcome to Python.orgThe official home of the Python Programming Languagehttps://www.python.org/我安装的是python3.11.4
安装时把环境路径勾选上,或者后面自己重新设置环境变量
2、下载opencv-python
按住win+R键,输入cmd,进入命令行界面
输入:pip install opencv-python
注:不要在命令行进入python环境后再输入上面的代码,会报错,我就犯了这个错误
查看opencv安装位置
pip show opencv-python
查看opencv版本
进入命令行界面,输入python,进入python环境,导入import cv2,输入cv2.__version__
安装vscode
vscode安装中文简体包(我英文很差),安装python包
显示图片:
import cv2 as cv
mypath = "C:\\Desktop\\opencv_python\\open_learn\\kit.jpeg"
img = cv.imread(mypath,1)
cv.imshow("img",img)
cv.waitKey(0)
cv.destroyAllWindows()
注:1、路径用"\\",而不是"\",否则会报错
2、确保路径正确,文件名后缀不要写错