I tried running the code below, it runs successfully but the images are not saved anywhere on the system. Does anyone know where the problem is or the solution?
import cv2
import time
# open the default camera
cap = cv2.VideoCapture(0)
# set the width and height of the frame
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
# set the start time
start_time = time.time()
# loop through the frames
print("looping through frames")
while True:
# capture a frame
ret, frame = cap.read()
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
# define the output file name and format
output_file = f'/Frame_{current_time}.jpg'
output_format = 'JPEG'
# check if the frame is captured successfully
if not ret:
break
# calculate the elapsed time
elapsed_time = time.time() - start_time
# check if 1 second has passed
if elapsed_time >= 1:
print("1 second passed")
# save the frame as an image file
cv2.imwrite(f'/TestFrames/{output_file}', frame)
print(output_file)
print("image saved")
# reset the start time
start_time = time.time()
print("time reset")
# display the frame
cv2.imshow('frame', frame)
# check for the 'q' key to quit
if cv2.waitKey(1) == ord('q'):
break
# release the camera and close all windows
cap.release()
cv2.destroyAllWindows()
I tried running the code below, it runs successfully but the images are not saved anywhere on the system.