import cv2 img = cv2.imread('selectROI_1.jpg') print('鼠标选择ROI,然后点击 enter键') r = cv2.selectROI('cv2.selectROI', img, True, False) roi = img[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])] cv2.imshow('roi', roi) cv2.waitKey(0) cv2.destroyAllWindows()