Reputation: 43
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
Upvotes: 0
Views: 1424
Reputation: 316
In this case you can use f-string, which is available in Python 3.6+.
out_path = f"/home/fraction/Desktop/extract_webcam_frames/frames/Frame{i}.jpg"
cv2.imwrite(out_path, frame)
i += 1
Upvotes: 1
Reputation:
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
Upvotes: 2