1.安装python 3.11.7
Python Release Python 3.11.7 | Python.org
安装成功后,查看版本为3.11.7
2.安装numpy
bash
pip install numpy
3.安装matplotlib
bash
pip install matplotlib
matplotlib库安装成功
4. 更新pip
bash
python -m pip install --upgrade pip
5.安装opencv-python
bash
pip install opencv-python
- 安装opencv-contrib-python
bash
pip install opencv-contrib-python
7. 测试opencv库导入与使用
8.使用opencv库加载并显示图像完整示例
python
# -*- coding: utf-8 -*-
#Created on Fri Apr 5 19:15:46 2024
#author: reverse
import cv2
import sys
if __name__ == "__main__":
if len(sys.argv) > 1:
image = cv2.imread(sys.argv[1],cv2.IMREAD_ANYCOLOR)
cv2.imshow("image", image)
else:
print ("Usge: Python load_image.py imagefile")
image = cv2.imread("R.png",cv2.IMREAD_UNCHANGED)
cv2.imshow("image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
9.使用python加载图像,将上面内容保存为load_image.py然后使用下面命令运行
bash
python load_image.py r.png
测试图像r.png
在PowerShell中运行
在命令提示符中运行