File size: 1,920 Bytes
a39d025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from inference import ObjectTrackerInference


tracker = ObjectTrackerInference(model_dir='models')


def track_object(video, x, y, width, height):
    try:
        if video is None:
            return None
        
        initial_bbox = [int(x), int(y), int(width), int(height)]
        
        output_path = 'tracked_output.mp4'
        result = tracker.track_video(video, initial_bbox, output_path, fps=30)
        
        return result
        
    except Exception as e:
        print(f"Error: {str(e)}")
        return None

with gr.Blocks(title="UAV Object Tracker") as demo:
    
    gr.Markdown("# 🎯 UAV Single Object Tracker")
    gr.Markdown("Upload a video and specify the initial bounding box to track an object.")
    
    with gr.Row():
        with gr.Column():
            video_input = gr.Video(label="Upload Video")
            
            gr.Markdown("### Initial Bounding Box Coordinates")
            with gr.Row():
                x_input = gr.Number(label="X (top-left)", value=100)
                y_input = gr.Number(label="Y (top-left)", value=100)
            with gr.Row():
                w_input = gr.Number(label="Width", value=50)
                h_input = gr.Number(label="Height", value=50)
            
            track_btn = gr.Button("Track Object", variant="primary")
        
        with gr.Column():
            video_output = gr.Video(label="Tracked Output")
    
    gr.Markdown("### 📖 Instructions")
    gr.Markdown("""
    1. Upload your video file
    2. Enter the initial bounding box coordinates (x, y, width, height) for the first frame
    3. Click 'Track Object' to process
    4. Download the tracked video from the output
    """)

    track_btn.click(
        fn=track_object,
        inputs=[video_input, x_input, y_input, w_input, h_input],
        outputs=video_output
    )

if __name__ == "__main__":
    demo.launch()