| 535 | |
| 536 | |
| 537 | def interpolate_frames(frame1, frame2, alpha): |
| 538 | gray1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY) |
| 539 | gray2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY) |
| 540 | |
| 541 | flow = cv2.calcOpticalFlowFarneback(gray1, gray2, None, pyr_scale=0.5, levels=3, winsize=15, iterations=3, poly_n=5, poly_sigma=1.2, flags=0) |
| 542 | h, w = flow.shape[:2] |
| 543 | |
| 544 | flow_map = -alpha * flow + np.indices((h, w)).transpose(1, 2, 0) |
| 545 | flow_map = flow_map.astype(np.float32) # Convert flow_map to float32 data type |
| 546 | return cv2.remap(frame1, flow_map, None, cv2.INTER_LINEAR) |
| 547 | |
| 548 | def interpolate_video(input_path, output_path, output_fps): |
| 549 | clip = VideoFileClip(input_path) |