MCPcopy Create free account
hub / github.com/CiaraStrawberry/TemporalKit / blend_batches

Function blend_batches

scripts/Berry_Method.py:504–533  ·  view source on GitHub ↗
(batch_before, current_batch,resolution, blend_start_ratio=0.9, blend_end_ratio=0.1)

Source from the content-addressed store, hash-verified

502
503
504def blend_batches(batch_before, current_batch,resolution, blend_start_ratio=0.9, blend_end_ratio=0.1):
505 blended_frames = []
506 num_frames = min(len (batch_before),len(current_batch))
507 decoded_batch_before = [cv2.cvtColor(utilityb.base64_to_texture(frame), cv2.COLOR_BGR2RGB) for frame in batch_before]
508 decoded_current_batch = [cv2.cvtColor(utilityb.base64_to_texture(frame), cv2.COLOR_BGR2RGB) for frame in current_batch]
509
510 #target_width, target_height = resolution, resolution
511 height, width = decoded_batch_before[0].shape[:2]
512 # Resize the images in decoded_batch_before and decoded_current_batch
513 decoded_batch_before = [cv2.resize(img, (width,height)) for img in decoded_batch_before]
514 decoded_current_batch = [cv2.resize(img, (width,height)) for img in decoded_current_batch]
515
516 output_folder = "moretemp"
517 if not os.path.exists(output_folder):
518 os.makedirs(output_folder)
519
520 if not num_frames > 1:
521 return [current_batch[0]]
522 for i in range(num_frames):
523 alpha = blend_start_ratio - (i / (num_frames - 1)) * (blend_start_ratio - blend_end_ratio)
524 blended_frame = cv2.addWeighted(decoded_batch_before[i], alpha, decoded_current_batch[i], 1 - alpha, 0)
525 print(f"blended frame {i}")
526
527 # Concatenate the two input frames and the blended frame horizontally
528 concatenated_frame = cv2.hconcat([decoded_batch_before[i], decoded_current_batch[i], blended_frame])
529
530 cv2.imwrite(os.path.join(output_folder, f"concatenated_{i}.png"), concatenated_frame)
531
532 blended_frames.append(blended_frame)
533 return blended_frames
534
535
536

Callers 1

process_videoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected