Update app.py
Browse files
app.py
CHANGED
@@ -43,7 +43,9 @@ def process_video(video_path, target, progress=gr.Progress()):
|
|
43 |
if not ret:
|
44 |
break
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
# Process single image
|
49 |
inputs = processor(text=[target], images=pil_img, return_tensors="pt", padding=True).to(device)
|
@@ -56,7 +58,7 @@ def process_video(video_path, target, progress=gr.Progress()):
|
|
56 |
max_score = 0
|
57 |
|
58 |
try:
|
59 |
-
font = ImageFont.truetype("arial.ttf",
|
60 |
except IOError:
|
61 |
font = ImageFont.load_default()
|
62 |
|
@@ -70,7 +72,7 @@ def process_video(video_path, target, progress=gr.Progress()):
|
|
70 |
annotation = f"{object_label}: {confidence}"
|
71 |
|
72 |
draw.rectangle(box, outline="red", width=2)
|
73 |
-
text_position = (box[0], box[1] -
|
74 |
draw.text(text_position, annotation, fill="white", font=font)
|
75 |
|
76 |
max_score = max(max_score, confidence)
|
@@ -80,7 +82,7 @@ def process_video(video_path, target, progress=gr.Progress()):
|
|
80 |
|
81 |
cap.release()
|
82 |
return processed_frames, frame_scores, None
|
83 |
-
|
84 |
def create_heatmap(frame_scores, current_frame):
|
85 |
plt.figure(figsize=(12, 3))
|
86 |
plt.imshow([frame_scores], cmap='hot_r', aspect='auto') # 'hot_r' for reversed hot colormap
|
|
|
43 |
if not ret:
|
44 |
break
|
45 |
|
46 |
+
# Resize the frame to 640x480
|
47 |
+
img_resized = cv2.resize(img, (640, 480))
|
48 |
+
pil_img = Image.fromarray(cv2.cvtColor(img_resized, cv2.COLOR_BGR2RGB))
|
49 |
|
50 |
# Process single image
|
51 |
inputs = processor(text=[target], images=pil_img, return_tensors="pt", padding=True).to(device)
|
|
|
58 |
max_score = 0
|
59 |
|
60 |
try:
|
61 |
+
font = ImageFont.truetype("arial.ttf", 20) # Reduced font size for smaller image
|
62 |
except IOError:
|
63 |
font = ImageFont.load_default()
|
64 |
|
|
|
72 |
annotation = f"{object_label}: {confidence}"
|
73 |
|
74 |
draw.rectangle(box, outline="red", width=2)
|
75 |
+
text_position = (box[0], box[1] - 20)
|
76 |
draw.text(text_position, annotation, fill="white", font=font)
|
77 |
|
78 |
max_score = max(max_score, confidence)
|
|
|
82 |
|
83 |
cap.release()
|
84 |
return processed_frames, frame_scores, None
|
85 |
+
|
86 |
def create_heatmap(frame_scores, current_frame):
|
87 |
plt.figure(figsize=(12, 3))
|
88 |
plt.imshow([frame_scores], cmap='hot_r', aspect='auto') # 'hot_r' for reversed hot colormap
|