BioShock BioShock - 1 year ago 94
Python Question

Save Video as Frames OpenCV{PY}

I would like to create a program which saves .jpg images taken from the webcam(frames).
What my program do for now is, opening a webcam, taking one and only one frame, and then everything stops.

What i would like to have is more than one frame
My error-code is this one:

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
count = 0

while True:
# Capture frame-by-frame
ret, frame =

# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imwrite("frame%d.jpg" % ret, frame) # save frame as JPEG file
count +=1

# Display the resulting frame
if cv2.waitKey(10):

Answer Source

Actually it sounds like you are always saving your image with the same name because you are concatenating ret instead of count in the imwrite method

try this :

name = "frame%d.jpg"%count
cv2.imwrite(name, frame)     # save frame as JPEG file