File size: 2,492 Bytes
a54527e
 
 
 
10877f8
a54527e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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()