Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import os
  2. import sys
  3. import cv2
  4.  
  5. def main(argv, argc):
  6.  
  7. if argc < 2:
  8. raise Exception('ERROR: No input_video inserted!')
  9. input_video = argv[1]
  10. if not os.path.isfile(input_video):
  11. raise Exception('ERROR: File does not exist!')
  12.  
  13. _filename, _ext = os.path.splitext(input_video)
  14. _basename = os.path.basename(_filename)
  15. output_dir = _filename
  16. if argc > 2:
  17. output_dir = sys.argv[2]
  18.  
  19. if not os.path.isdir(output_dir):
  20. os.makedirs(output_dir)
  21.  
  22. vcap = cv2.VideoCapture(input_video)
  23.  
  24. cont_frames = 0
  25. while True:
  26. cont_frames += 1
  27. ret, frame = vcap.read()
  28. if ret:
  29. img_filename = 'frame_' + str(cont_frames) + '_' + _basename + '.jpg'
  30. img_filename = os.path.join(output_dir, img_filename)
  31. cv2.imwrite(img_filename, frame)
  32. print('saving frame... ' + img_filename)
  33. else:
  34. break
  35.  
  36.  
  37. if __name__ == '__main__':
  38. print('starting app...')
  39. main(sys.argv, len(sys.argv))
  40. print('success!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement