You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
872 B

6 years ago
  1. import random, string
  2. import numpy as np
  3. import cv2
  4. def generate_id(length=32):
  5. return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
  6. cap = cv2.VideoCapture(1)
  7. cars = [
  8. [(420, 375), (500, 480)],
  9. [(505, 340), (590, 440)],
  10. [(415, 240), (495, 330)],
  11. [(485, 235), (550, 320)]
  12. ]
  13. ambulance = [(250, 130), (400, 240)]
  14. while(True):
  15. # Capture frame-by-frame
  16. ret, frame = cap.read()
  17. key = cv2.waitKey(1) & 0xFF
  18. if key == ord('s'):
  19. cv2.imwrite(generate_id(12) + ".jpg", frame[100:600, 240:600])
  20. for i in cars:
  21. cv2.rectangle(frame, *i, (0, 0, 255), 2)
  22. cv2.rectangle(frame, *ambulance, (255, 0, 0), 2)
  23. frame = frame[100:600, 240:600]
  24. cv2.imshow('frame', frame)
  25. if key == ord('q'):
  26. break
  27. # When everything done, release the capture
  28. cap.release()
  29. cv2.destroyAllWindows()