Spaces:
Running
on
Zero
Running
on
Zero
Martin Tomov
commited on
another attempt to fix the output
Browse files
app.py
CHANGED
@@ -34,21 +34,16 @@ class DetectionResult:
|
|
34 |
|
35 |
@classmethod
|
36 |
def from_dict(cls, detection_dict: Dict) -> 'DetectionResult':
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
box
|
44 |
-
|
45 |
-
ymin=detection_dict['box']['ymin'],
|
46 |
-
xmax=detection_dict['box']['xmax'],
|
47 |
-
ymax=detection_dict['box']['ymax']
|
48 |
-
)
|
49 |
)
|
50 |
-
|
51 |
-
raise ValueError(f"Missing key in detection dictionary: {e}")
|
52 |
|
53 |
def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
|
54 |
image_cv2 = np.array(image) if isinstance(image, Image.Image) else image
|
@@ -167,7 +162,7 @@ def draw_classification_boxes(image_with_insects, detections):
|
|
167 |
label = detection.label
|
168 |
score = detection.score
|
169 |
box = detection.box
|
170 |
-
color =
|
171 |
|
172 |
cv2.rectangle(image_with_insects, (box.xmin, box.ymin), (box.xmax, box.ymax), color, 2)
|
173 |
(text_width, text_height), baseline = cv2.getTextSize(f"{label}: {score:.2f}", cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2)
|
@@ -185,7 +180,7 @@ def draw_classification_boxes(image_with_insects, detections):
|
|
185 |
cv2.FONT_HERSHEY_SIMPLEX,
|
186 |
0.5,
|
187 |
(255, 255, 255),
|
188 |
-
|
189 |
)
|
190 |
return image_with_insects
|
191 |
|
|
|
34 |
|
35 |
@classmethod
|
36 |
def from_dict(cls, detection_dict: Dict) -> 'DetectionResult':
|
37 |
+
return cls(
|
38 |
+
score=detection_dict['score'],
|
39 |
+
label=detection_dict['label'],
|
40 |
+
box=BoundingBox(
|
41 |
+
xmin=detection_dict['box']['xmin'],
|
42 |
+
ymin=detection_dict['box']['ymin'],
|
43 |
+
xmax=detection_dict['box']['xmax'],
|
44 |
+
ymax=detection_dict['box']['ymax']
|
|
|
|
|
|
|
|
|
45 |
)
|
46 |
+
)
|
|
|
47 |
|
48 |
def annotate(image: Union[Image.Image, np.ndarray], detection_results: List[DetectionResult]) -> np.ndarray:
|
49 |
image_cv2 = np.array(image) if isinstance(image, Image.Image) else image
|
|
|
162 |
label = detection.label
|
163 |
score = detection.score
|
164 |
box = detection.box
|
165 |
+
color = (0, 255, 255) # Yellow color for bounding box
|
166 |
|
167 |
cv2.rectangle(image_with_insects, (box.xmin, box.ymin), (box.xmax, box.ymax), color, 2)
|
168 |
(text_width, text_height), baseline = cv2.getTextSize(f"{label}: {score:.2f}", cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2)
|
|
|
180 |
cv2.FONT_HERSHEY_SIMPLEX,
|
181 |
0.5,
|
182 |
(255, 255, 255),
|
183 |
+
2
|
184 |
)
|
185 |
return image_with_insects
|
186 |
|