RacingDemo / src /main.py
Vlad Bastina
merge
10877f8
from models.frame_extractor import extract_frame_timestamp
from models.bounding_box_extractor import extract_bounding_box
from models.catchphrase_extractor import extract_catchphrase
from models.bet_extractor import extract_bet_amount
from src.utils import extract_frame , center_bbox_in_circle , overlay_image_bottom_right , overlay_image_top_left, annotate_image_with_phrase_and_label
import os
import re
def main():
video_path = "race_vid.mp4"
image_path = "tmp/extracted_frame.png"
background_path = "path/to/your/background.png"
mask_path = "path/to/your/mask.png"
output_path = "path/to/output/image.png"
# Extract frame timestamp
response , uploaded_obj = extract_frame_timestamp(video_path) # Extract frame at 10 seconds
print(f"Response from frame extraction: {response}")
timestamp_match = re.search(r'\*\*Winning Timestamp:\*\*\s*(\d{2}:\d{2}:\d{2}\.\d{3})', response)
timestamp = timestamp_match.group(1) if timestamp_match else None
# Extract the short description
description_match = re.search(r'\*\*Short description of the winner:\*\*\s*(.*?)\s*(?=\*\*|$)', response, re.DOTALL)
description = description_match.group(1).strip() if description_match else None
print(f"Extracted timestamp: {timestamp}")
print(f"Extracted description: {description}")
extract_frame(video_path, timestamp, image_path)
# # Extract bounding box
response = extract_bounding_box(image_path,description)
bbox_match = re.search(r'\((\d+),\s*(\d+),\s*(\d+),\s*(\d+)\)', response)
bbox = tuple(map(int, bbox_match.groups())) if bbox_match else None
print(f"Extracted bounding box: {bbox}")
center_bbox_in_circle(image_path, bbox,image_path)
overlay_image_bottom_right(image_path,"assets/corner.png",image_path)
overlay_image_top_left(image_path,"assets/GetOn_Logo.png",image_path)
catchphrases = extract_catchphrase(video_path)
pattern = r'["](.*?)["]'
phrases = re.findall(pattern, catchphrases)
# Extract bet amount
bet_amounts = extract_bet_amount(video_path)
pattern = r'\*\*Exact Label Text:\*\* "([^"]+)"'
labels = re.findall(pattern, bet_amounts)
phrase = phrases[0] if phrases else "No catchphrase found"
label = labels[0] if labels else "No bet label found"
annotate_image_with_phrase_and_label(image_path,image_path,phrase,label)
if __name__ == "__main__":
main()