Skip to content

Instantly share code, notes, and snippets.

@Shreyz-max
Created March 15, 2021 10:44
Show Gist options
  • Save Shreyz-max/5e792c7f1e773fd4b93443f28970168e to your computer and use it in GitHub Desktop.
Save Shreyz-max/5e792c7f1e773fd4b93443f28970168e to your computer and use it in GitHub Desktop.
extract images
def video_to_frames(video):
path = os.path.join(config.test_path, 'temporary_images')
if os.path.exists(path):
shutil.rmtree(path)
os.makedirs(path)
video_path = os.path.join(config.test_path, 'video', video)
count = 0
image_list = []
# Path to video file
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
ret, frame = cap.read()
if ret is False:
break
cv2.imwrite(os.path.join(config.test_path, 'temporary_images', 'frame%d.jpg' % count), frame)
image_list.append(os.path.join(config.test_path, 'temporary_images', 'frame%d.jpg' % count))
count += 1
cap.release()
cv2.destroyAllWindows()
return image_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment