data_generation.py 632 B

12345678910111213141516171819202122232425262728
  1. '''This script is for generating data
  2. 1. Provide desired path to store images.
  3. 2. Press 'c' to capture image and display it.
  4. 3. Press any button to continue.
  5. 4. Press 'q' to quit.
  6. '''
  7. import cv2
  8. camera = cv2.VideoCapture(0)
  9. ret, img = camera.read()
  10. #path = "/home/abhishek/stuff/object_detection/explore/aruco_data/" # !!
  11. count = 0
  12. while True:
  13. name = path + str(count)+".jpg"
  14. ret, img = camera.read()
  15. cv2.imshow("img", img)
  16. if cv2.waitKey(20) & 0xFF == ord('c'):
  17. cv2.imwrite(name, img)
  18. cv2.imshow("img", img)
  19. count += 1
  20. if cv2.waitKey(0) & 0xFF == ord('q'):
  21. break;