Python 3 OpenCV Script to Extract Video Frames From Webcam and Save as PNG/JPG Images on Local PC Full Project For Beginners

 

 

pip install opencv-python

 

 

 

 

 

 

main.py

 

 

import cv2

# Opens the inbuilt camera of laptop to capture video.
cap = cv2.VideoCapture(0)
i = 0

while(cap.isOpened()):
    ret, frame = cap.read()
    
    # This condition prevents from infinte looping
    # incase video ends.
    if ret == False:
        break
    
    # Save Frame by Frame into disk using imwrite method
    cv2.imwrite('Frame'+str(i)+'.jpg', frame)
    i += 1

cap.release()
cv2.destroyAllWindows()

Leave a Reply