123456789101112131415161718192021222324252627282930313233343536373839 |
- import os
- import matplotlib.image as mpimg
- import matplotlib.pyplot as plt
- current_file = None
- def onclick(event):
- if event.dblclick:
- print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
- (event.button, event.x, event.y, event.xdata, event.ydata))
- import csv
- with open(current_file + ".csv", 'a') as csvfile:
- spamwriter = csv.writer(csvfile, delimiter=' ',
- quotechar='|', quoting=csv.QUOTE_MINIMAL)
- spamwriter.writerow([str(event.xdata), str(event.ydata)])
- def argsProcessor():
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("-v", "--video_imgs", help="DataPath")
- return parser.parse_args()
- args = argsProcessor()
- dir = args.video_imgs
- for image in os.listdir(dir):
- if image.endswith("jpg") or image.endswith("JPG"):
- current_file = dir + "/" + image
- if os.path.isfile(current_file + ".csv"):
- print(current_file + ".csv file already exists")
- pass
- else:
- fig = plt.figure()
- cid = fig.canvas.mpl_connect('button_press_event', onclick)
- print(current_file)
- img = mpimg.imread(current_file)
- plt.imshow(img)
- plt.show()
|