muhammadsalmanalfaridzi commited on
Commit
64e8634
·
verified ·
1 Parent(s): d735818

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -85,11 +85,11 @@ def detect_combined(image):
85
  result_text = "Product Nestle\n\n"
86
  for class_name, count in nestle_class_count.items():
87
  result_text += f"{class_name}: {count}\n"
88
- result_text += f"\nTotal Product Nestle: {total_nestle}\n\n"
89
 
90
  result_text += "Competitor Products\n\n"
91
  if competitor_class_count:
92
- result_text += f"Total Competitor: {total_competitor}\n" # Hanya total, tidak per kelas
93
  else:
94
  result_text += "No competitors detected\n"
95
 
@@ -106,12 +106,17 @@ def detect_combined(image):
106
  # Kompetitor (Merah) dengan nama 'unclassified'
107
  for comp in competitor_boxes:
108
  x1, y1, x2, y2 = comp['box']
109
- # Ubah nama kelas menjadi 'unclassified' jika sesuai dengan kategori yang disebutkan
110
- display_name = "unclassified" if comp['class'] in ["beverage . bottle . cans"] else comp['class']
111
- cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0,0,255), 2)
112
- cv2.putText(img, f"{display_name} {comp['confidence']:.2f}",
113
- (int(x1), int(y1-10)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255), 2)
114
-
 
 
 
 
 
115
  output_path = "/tmp/combined_output.jpg"
116
  cv2.imwrite(output_path, img)
117
 
 
85
  result_text = "Product Nestle\n\n"
86
  for class_name, count in nestle_class_count.items():
87
  result_text += f"{class_name}: {count}\n"
88
+ result_text += f"\nTotal Products Nestle: {total_nestle}\n\n"
89
 
90
  result_text += "Competitor Products\n\n"
91
  if competitor_class_count:
92
+ result_text += f"Total Unclassified Products: {total_competitor}\n" # Hanya total, tidak per kelas
93
  else:
94
  result_text += "No competitors detected\n"
95
 
 
106
  # Kompetitor (Merah) dengan nama 'unclassified'
107
  for comp in competitor_boxes:
108
  x1, y1, x2, y2 = comp['box']
109
+
110
+ # Define a list of target classes to rename
111
+ unclassified_classes = ["beverage", "cans", "bottle"]
112
+
113
+ # Normalize the class name to be case-insensitive and check if it's in the unclassified list
114
+ display_name = "unclassified" if any(class_name in comp['class'].lower() for class_name in unclassified_classes) else comp['class']
115
+
116
+ cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 0, 255), 2)
117
+ cv2.putText(img, f"{display_name} {comp['confidence']:.2f}",
118
+ (int(x1), int(y1-10)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
119
+
120
  output_path = "/tmp/combined_output.jpg"
121
  cv2.imwrite(output_path, img)
122