Spaces:
Sleeping
Sleeping
Update model_3.py
Browse files- model_3.py +6 -6
model_3.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#
|
2 |
import os
|
3 |
import cv2
|
4 |
import numpy as np
|
@@ -42,10 +42,10 @@ if 'StatefulPartitionedCall' in outname:
|
|
42 |
else:
|
43 |
boxes_idx, classes_idx, scores_idx = 0, 1, 2
|
44 |
|
45 |
-
def perform_detection(image):
|
46 |
imH, imW, _ = image.shape
|
47 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
48 |
-
image_resized = cv2.resize(image_rgb,
|
49 |
input_data = np.expand_dims(image_resized, axis=0)
|
50 |
|
51 |
if floating_model:
|
@@ -66,7 +66,7 @@ def perform_detection(image):
|
|
66 |
ymax = int(min(imH, (boxes[i][2] * imH)))
|
67 |
xmax = int(min(imW, (boxes[i][3] * imW)))
|
68 |
|
69 |
-
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (
|
70 |
object_name = labels[int(classes[i])]
|
71 |
label = '%s: %d%%' % (object_name, int(scores[i] * 100))
|
72 |
labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2)
|
@@ -79,7 +79,7 @@ def perform_detection(image):
|
|
79 |
|
80 |
def detect_image(input_image):
|
81 |
image = np.array(input_image)
|
82 |
-
result_image = perform_detection(image)
|
83 |
return Image.fromarray(result_image)
|
84 |
|
85 |
def detect_video(input_video):
|
@@ -91,7 +91,7 @@ def detect_video(input_video):
|
|
91 |
if not ret:
|
92 |
break
|
93 |
|
94 |
-
result_frame = perform_detection(frame)
|
95 |
frames.append(result_frame)
|
96 |
|
97 |
cap.release()
|
|
|
1 |
+
# model_3.py
|
2 |
import os
|
3 |
import cv2
|
4 |
import numpy as np
|
|
|
42 |
else:
|
43 |
boxes_idx, classes_idx, scores_idx = 0, 1, 2
|
44 |
|
45 |
+
def perform_detection(image, target_size=(640, 640)):
|
46 |
imH, imW, _ = image.shape
|
47 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
48 |
+
image_resized = cv2.resize(image_rgb, target_size)
|
49 |
input_data = np.expand_dims(image_resized, axis=0)
|
50 |
|
51 |
if floating_model:
|
|
|
66 |
ymax = int(min(imH, (boxes[i][2] * imH)))
|
67 |
xmax = int(min(imW, (boxes[i][3] * imW)))
|
68 |
|
69 |
+
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 0, 255), 2) # Red color for bounding box
|
70 |
object_name = labels[int(classes[i])]
|
71 |
label = '%s: %d%%' % (object_name, int(scores[i] * 100))
|
72 |
labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2)
|
|
|
79 |
|
80 |
def detect_image(input_image):
|
81 |
image = np.array(input_image)
|
82 |
+
result_image = perform_detection(image, target_size=(640, 640))
|
83 |
return Image.fromarray(result_image)
|
84 |
|
85 |
def detect_video(input_video):
|
|
|
91 |
if not ret:
|
92 |
break
|
93 |
|
94 |
+
result_frame = perform_detection(frame, target_size=(640, 640))
|
95 |
frames.append(result_frame)
|
96 |
|
97 |
cap.release()
|