brxerq commited on
Commit
8966657
1 Parent(s): 5cdf808

Update model_1.py

Browse files
Files changed (1) hide show
  1. model_1.py +9 -1
model_1.py CHANGED
@@ -42,6 +42,12 @@ if 'StatefulPartitionedCall' in outname:
42
  else:
43
  boxes_idx, classes_idx, scores_idx = 0, 1, 2
44
 
 
 
 
 
 
 
45
  def perform_detection(image):
46
  imH, imW, _ = image.shape
47
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
@@ -66,8 +72,10 @@ def perform_detection(image):
66
  ymax = int(min(imH, (boxes[i][2] * imH)))
67
  xmax = int(min(imW, (boxes[i][3] * imW)))
68
 
69
- cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (10, 255, 0), 2)
70
  object_name = labels[int(classes[i])]
 
 
 
71
  label = '%s: %d%%' % (object_name, int(scores[i] * 100))
72
  labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2)
73
  label_ymin = max(ymin, labelSize[1] + 10)
 
42
  else:
43
  boxes_idx, classes_idx, scores_idx = 0, 1, 2
44
 
45
+ # Define the color mapping
46
+ color_mapping = {
47
+ 'Misalignment class': (0, 0, 255), # Red for misalignment
48
+ 'Empty class': (0, 255, 0) # Green for empty
49
+ }
50
+
51
  def perform_detection(image):
52
  imH, imW, _ = image.shape
53
  image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 
72
  ymax = int(min(imH, (boxes[i][2] * imH)))
73
  xmax = int(min(imW, (boxes[i][3] * imW)))
74
 
 
75
  object_name = labels[int(classes[i])]
76
+ color = color_mapping.get(object_name, (10, 255, 0)) # Default color if not specified
77
+
78
+ cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, 2)
79
  label = '%s: %d%%' % (object_name, int(scores[i] * 100))
80
  labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2)
81
  label_ymin = max(ymin, labelSize[1] + 10)