2 bedroom, stove, refrigerator, washer & dryer and garage. # Calculate the duration of the video in secondsĬap.set(cv2.CAP_PROP_POS_MSEC, second * 1000) # optionalĬap.set(cv2. Spacious upper level duplex with private entry in quiet part of Antigo.
In the documentation linked above is possible to see that the way to set a specific time in the VideoCapture is: milliseconds = 1000Ĭap.set(cv2.CAP_PROP_POS_MSEC, milliseconds)Īnd like before a full example that read a frame each second che be achieved in this way: import cv2 While success and frame_number <= frame_count:Ĭap.set(cv2.CAP_PROP_POS_FRAMES, frame_number) # Get the total numer of frames in the video.įrame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)Ĭap.set(cv2.CAP_PROP_POS_FRAMES, frame_number) # optional Notice that you don't have to pass to the function frame - 1 because, as the documentation says, the flag CAP_PROP_POS_FRAMES rapresent the "0-based index of the frame to be decoded/captured next".Ĭoncluding a full example where i want to read a frame at each second is: import cv2 # When everything done, release the captureįrom the documentation of the VideoCaptureProperties ( docs) is possible to see that the way to set the frame in the VideoCapture is: frame = 30 #Cut the video extension to have the name of the videoĬv2.imshow(my_video_name+' frame '+ str(frame_seq),gray)Ĭv2.imwrite(my_video_name+'_frame_'+str(frame_seq)+'.jpg',gray) Gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
If you set frame 749 above then the code will return the last frame. #The second argument defines the frame number in range 0.0-1.0 #Number 2 defines flag CV_CAP_PROP_POS_FRAMES which is a 0-based index of the frame to be decoded/captured next. #The first argument of cap.set(), number 2 defines that parameter for setting the frame selection. #So make sure that you have the right parameters for the right video!įrame_no = (frame_seq /(time_length*fps)) #BE CAREFUL! Each video has different time length and frame rate. In case you want to select other frame change value 749.
#Here we select the last frame as frame sequence=749. #For more info about the video flags see here: #The examined frame must get a value from 0 to 749. #In this example we have a video of 30 seconds having 25 frames per seconds, thus we have 750 frames. Video_name = input("Please give the video name including its extension. #Ginen video name must be in quotes, e.g. The correct solution is: import numpy as np The video parameters should be given as integers.