def main():
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
# load the image, clone it, and setup the mouse callback function
image = cv2.imread(args["image"])
clone = image.copy()
images = [clone, image]
ref_pt = [None, None]
cv2.namedWindow("image")
cv2.setMouseCallback("image", make_mouse_callback(images, ref_pt))
# keep looping until the 'q' key is pressed
while True:
# display the image and wait for a keypress
cv2.imshow("image", images[1])
key = cv2.waitKey(1) & 0xFF
# if the 'c' key is pressed, break from the loop
if key == ord("c"):
if ref_pt[1] is None:
continue
roi = clone[ref_pt[0][1]:ref_pt[1][1], ref_pt[0][0]:ref_pt[1][0]]
interactive_save(roi)
elif key == ord("q"):
break
# if there are two reference points, then crop the region of interest
# from teh image and display it
# close all open windows
cv2.destroyAllWindows()
评论列表
文章目录