xcurvnubaim commited on
Commit
480872a
·
1 Parent(s): 29a6070

fix: continue when object detected

Browse files
Files changed (1) hide show
  1. main.py +4 -0
main.py CHANGED
@@ -51,7 +51,9 @@ def animal_detect_and_classify(img_path):
51
  # Iterate over the detected objects
52
  # Iterate over detections
53
  for result in detect_results:
 
54
  for box in result.boxes:
 
55
  # print(box)
56
  # Crop the RoI
57
  x1, y1, x2, y2 = map(int, box.xyxy[0])
@@ -78,6 +80,8 @@ def animal_detect_and_classify(img_path):
78
  predicted_labels = [labels[np.argmax(pred)] if np.max(pred) >= threshold else "animal" for pred in prediction]
79
  print(predicted_labels)
80
  combined_results.append(((x1, y1, x2, y2), predicted_labels))
 
 
81
  y2, x2, _ = img.shape
82
  detect_img = img[0:y2, 0:x2]
83
  detect_img = cv2.cvtColor(detect_img, cv2.COLOR_BGR2RGB)
 
51
  # Iterate over the detected objects
52
  # Iterate over detections
53
  for result in detect_results:
54
+ flag = False
55
  for box in result.boxes:
56
+ flag = True
57
  # print(box)
58
  # Crop the RoI
59
  x1, y1, x2, y2 = map(int, box.xyxy[0])
 
80
  predicted_labels = [labels[np.argmax(pred)] if np.max(pred) >= threshold else "animal" for pred in prediction]
81
  print(predicted_labels)
82
  combined_results.append(((x1, y1, x2, y2), predicted_labels))
83
+ if flag:
84
+ continue
85
  y2, x2, _ = img.shape
86
  detect_img = img[0:y2, 0:x2]
87
  detect_img = cv2.cvtColor(detect_img, cv2.COLOR_BGR2RGB)