import cv2 # 读取图片 img = cv2.imread('demo.png') # h、w为想要截取的图片大小 h, w = 35, 170 # 坐标 x, y= 500, 425 targetImg = img[(y):(y + h), (x):(x + w)] cv2.imwrite('targetImg.png', targetImg)