I use OpenCV to read in the frames of many FLV videos. The part where I do the reading is:
def frame_preprocessing(image, left=320, right=600, top=220, bottom=348):
height, width, channel = image.shape
return image[top:height-bottom,left:width-right,:]
# Create a VideoCapture object and read from input file
cap = cv2.VideoCapture(file_path)
if cap.isOpened(): # Check if camera opened successfully
ret, frame = cap.read()
if ret == True:
frame = frame_preprocessing(frame).astype('int8')
else:
print("Error opening video stream or file")
frames = np.empty(shape=(nb_frames_in_file,) + frame.shape, dtype=np.int8)
frames[0, :, :, :] = frame
nr_frame = 1
# Read until video is completed
while (cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
frames[nr_frame, :, :, :] = frame_preprocessing(frame).astype('int8')
nr_frame = nr_frame + 1
else:
break
# When everything done, release the video capture object
cap.release()
Instead of using the function frame_preprocessing
to cut out a certain section of the frames, I would like to not load the entire image in the first place. How can I tell OpenCV to only read a certain section of the frames?