The following steps need to be performed:
- Implement an extract_frames() function to extract the first 200 frames (at most) from a video passed as input to the function:
def extract_frames(vid_file):
vidcap = cv2.VideoCapture(vid_file)
success,image = vidcap.read()
i = 1
success = True
while success and i <= 200:
cv2.imwrite('images/exposure/vid_{}.jpg'.format(i), image)
success,image = vidcap.read()
i += 1
- Call the function to save all of the frames (as .jpg) extracted from the video of the waterfall in Godafost (Iceland) to the exposure folder:
extract_frames('images/godafost.mp4') #cloud.mp4
- Read all the .jpg files from the exposure folder; read them one by one (as float); split each image into B, G, and R channels; compute a running sum of the color channels; and finally, compute average values for the color channels:
imfiles = glob('images/exposure/*.jpg')
nfiles = len(imfiles)
R1, G1, B1 = 0, 0, 0
for i in range(nfiles):
image = cv2.imread(imfiles[i]).astype(float)
(B, G, R) = cv2.split(image)
R1 += R
B1 += B
G1 += G
R1, G1, B1 = R1 / nfiles, G1 / nfiles, B1 / nfiles
- Merge the average values of the color channels obtained and save the final output image:
final = cv2.merge([B1, G1, R1])
cv2.imwrite('images/godafost.png', final)
The following photo shows one of the extracted input frames:
If you run the preceding code block, you will obtain a long exposure-like image like the one shown here:
Notice the continuous effects in the clouds and the waterfall.