首先搭建OpenCV环境
打开cmd模式
如果已经装好Python就直接输入
pip install opencv-python
pip install opencv-contrib-python(进阶选装)
等待大概十分钟 装后测试:
import cv2 as cv src =cv.imread("C:\\Users\\william\\Pictures\\go.jpg") cv.namedWindow("input image",cv.WINDOW_AUTOSIZE) cv.imshow("input image",src) cv.waitKey(0) cv.destroyAllWindows()
这里路径有3种表示方式(直接复制路径会报错)
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position
2-3: truncated \UXXXXXXXX escape
im = Image.open('C:\\Users\\William\\Pictures\\go.jpg')
im = Image.open(r'C:\Users\William\Pictures\go.jpg')
im = Image.open(r'C:/Users/William/Pictures/go.jpg')
测试效果: