Update app.py
Browse files
app.py
CHANGED
|
@@ -92,45 +92,45 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
|
|
| 92 |
image = frame.to_ndarray(format="bgr24")
|
| 93 |
|
| 94 |
# Run inference
|
| 95 |
-
blob = cv2.dnn.blobFromImage(
|
| 96 |
-
|
| 97 |
-
)
|
| 98 |
-
net.setInput(blob)
|
| 99 |
-
output = net.forward()
|
| 100 |
-
|
| 101 |
-
h, w = image.shape[:2]
|
| 102 |
-
|
| 103 |
-
# Convert the output array into a structured form.
|
| 104 |
-
output = output.squeeze() # (1, 1, N, 7) -> (N, 7)
|
| 105 |
-
output = output[output[:, 2] >= score_threshold]
|
| 106 |
-
detections = [
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
]
|
| 115 |
-
|
| 116 |
-
# Render bounding boxes and captions
|
| 117 |
-
for detection in detections:
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
result_queue.put(detections)
|
| 134 |
|
| 135 |
return av.VideoFrame.from_ndarray(image, format="bgr24")
|
| 136 |
|
|
|
|
| 92 |
image = frame.to_ndarray(format="bgr24")
|
| 93 |
|
| 94 |
# Run inference
|
| 95 |
+
# blob = cv2.dnn.blobFromImage(
|
| 96 |
+
# cv2.resize(image, (128, 128)), 0.007843, (128, 128), 127.5
|
| 97 |
+
# )
|
| 98 |
+
# net.setInput(blob)
|
| 99 |
+
# output = net.forward()
|
| 100 |
+
|
| 101 |
+
# h, w = image.shape[:2]
|
| 102 |
+
|
| 103 |
+
# # Convert the output array into a structured form.
|
| 104 |
+
# output = output.squeeze() # (1, 1, N, 7) -> (N, 7)
|
| 105 |
+
# output = output[output[:, 2] >= score_threshold]
|
| 106 |
+
# detections = [
|
| 107 |
+
# Detection(
|
| 108 |
+
# class_id=int(detection[1]),
|
| 109 |
+
# label=CLASSES[int(detection[1])],
|
| 110 |
+
# score=float(detection[2]),
|
| 111 |
+
# box=(detection[3:7] * np.array([w, h, w, h])),
|
| 112 |
+
# )
|
| 113 |
+
# for detection in output
|
| 114 |
+
# ]
|
| 115 |
+
|
| 116 |
+
# # Render bounding boxes and captions
|
| 117 |
+
# for detection in detections:
|
| 118 |
+
# caption = f"{detection.label}: {round(detection.score * 100, 2)}%"
|
| 119 |
+
# color = COLORS[detection.class_id]
|
| 120 |
+
# xmin, ymin, xmax, ymax = detection.box.astype("int")
|
| 121 |
+
|
| 122 |
+
# cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, 2)
|
| 123 |
+
# cv2.putText(
|
| 124 |
+
# image,
|
| 125 |
+
# caption,
|
| 126 |
+
# (xmin, ymin - 15 if ymin - 15 > 15 else ymin + 15),
|
| 127 |
+
# cv2.FONT_HERSHEY_SIMPLEX,
|
| 128 |
+
# 0.5,
|
| 129 |
+
# color,
|
| 130 |
+
# 2,
|
| 131 |
+
# )
|
| 132 |
+
|
| 133 |
+
result_queue.put([]) #detections)
|
| 134 |
|
| 135 |
return av.VideoFrame.from_ndarray(image, format="bgr24")
|
| 136 |
|