Home > database >  how to write frames into folder using opencv
how to write frames into folder using opencv

Time:03-15

Extracting frames from live webcam video and save in common space. but how to write frames in specific folder using opencv

code :

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 infinite 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()

i tried like this but i wont worked for me

out_path = "/home/fraction/Desktop/extract_webcam_frames/frames"
path = out_path 
cv2.imwrite(os.path.join(path    str(i) '.jpg' , frame)
i  = 1

How to resolve this issue using opencv python

CodePudding user response:

You need to write the path correctly.

out_path = "/home/fraction/Desktop/extract_webcam_frames/frames"
frame_name = 'Frame' str(i) '.jpg'
cv2.imwrite(os.path.join(out_path, frame_name), frame)
i  = 1
  • Related