在命令行中使用 pip install opencv-python
出现 Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting opencv-python
Downloading https://mirrors.aliyun.com/pypi/packages/38/d2/3e8c13ffc37ca5ebc6f382b242b44acb43eb489042e1728407ac3904e72f/opencv_python-4.8.1.78-cp37-abi3-win_amd64.whl (38
.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.1/38.1 MB 3.3 MB/s eta 0:00:00
Collecting numpy>=1.21.2 (from opencv-python)
Downloading https://mirrors.aliyun.com/pypi/packages/cc/05/ef9fc04adda45d537619ea956bc33489f50a46badc949c4280d8309185ec/numpy-1.26.0-cp310-cp310-win_amd64.whl (15.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.8/15.8 MB 3.4 MB/s eta 0:00:00
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.26.0 opencv-python-4.8.1.78
表示安装完成可以使用opencv了
中间出现错误可以 pip换源重新运行 pip install opencv-python
运行以下代码
import cv2
image_path = 'D:\\1.jpg' # 换成图片文件路径
image = cv2.imread(image_path)
cv2.imshow("image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
出现一个图片