No Description

frame_extract.py 685B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor
  4. This is a temporary script file.
  5. """
  6. # Import the necessary packages
  7. import cv2
  8. import os
  9. import re
  10. # get working directory
  11. loc = os.path.abspath('')
  12. inputFile = loc+'/trafficCounter/inputs/625_201709301058.mp4'
  13. camera = re.match(r".*/(\d+)_.*", inputFile)
  14. camera = camera.group(1)
  15. vidcap = cv2.VideoCapture(inputFile)
  16. success,image = vidcap.read()
  17. count = 0;
  18. while success:
  19. success,image = vidcap.read()
  20. # save frame as JPEG file
  21. cv2.imwrite(loc+"/trafficCounter/outputs/"+camera+"_frame%d.jpg" % count, image)
  22. if cv2.waitKey(10) == 27: # exit if Escape is hit
  23. break
  24. count += 1