Martin Tomov commited on
Commit
e7ab241
·
verified ·
1 Parent(s): 484046d

another attempt to fix the output

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -34,21 +34,16 @@ class DetectionResult:
34
 
35
  @classmethod
36
  def from_dict(cls, detection_dict: Dict) -> 'DetectionResult':
37
- # Debugging: Print the dictionary to see its structure
38
- print("Detection Dictionary:", detection_dict)
39
- try:
40
- return cls(
41
- score=detection_dict['score'],
42
- label=detection_dict['label'],
43
- box=BoundingBox(
44
- xmin=detection_dict['box']['xmin'],
45
- ymin=detection_dict['box']['ymin'],
46
- xmax=detection_dict['box']['xmax'],
47
- ymax=detection_dict['box']['ymax']
48
- )
49
  )
50
- except KeyError as e:
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 = np.random.randint(0, 256, size=3).tolist()
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
- 2
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