label.py 1014 B

1234567891011121314151617181920212223242526272829303132
  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. dir = "../data1/"
  15. for image in os.listdir(dir):
  16. if image.endswith("jpg") or image.endswith("JPG"):
  17. if os.path.isfile(dir + image + ".csv"):
  18. pass
  19. else:
  20. fig = plt.figure()
  21. cid = fig.canvas.mpl_connect('button_press_event', onclick)
  22. print(dir + image)
  23. current_file = dir + image
  24. img = mpimg.imread(dir + image)
  25. plt.imshow(img)
  26. plt.show()