label.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import matplotlib.image as mpimg
  3. import matplotlib.pyplot as plt
  4. current_file = None
  5. def onclick(event):
  6. if event.dblclick:
  7. print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
  8. (event.button, event.x, event.y, event.xdata, event.ydata))
  9. import csv
  10. with open(current_file + ".csv", 'a') as csvfile:
  11. spamwriter = csv.writer(csvfile, delimiter=' ',
  12. quotechar='|', quoting=csv.QUOTE_MINIMAL)
  13. spamwriter.writerow([str(event.xdata), str(event.ydata)])
  14. def argsProcessor():
  15. import argparse
  16. parser = argparse.ArgumentParser()
  17. parser.add_argument("-v", "--video_imgs", help="DataPath")
  18. return parser.parse_args()
  19. args = argsProcessor()
  20. dir = args.video_imgs
  21. for image in os.listdir(dir):
  22. if image.endswith("jpg") or image.endswith("JPG"):
  23. current_file = dir + "/" + image
  24. if os.path.isfile(current_file + ".csv"):
  25. print(current_file + ".csv file already exists")
  26. pass
  27. else:
  28. fig = plt.figure()
  29. cid = fig.canvas.mpl_connect('button_press_event', onclick)
  30. print(current_file)
  31. img = mpimg.imread(current_file)
  32. plt.imshow(img)
  33. plt.show()