Jamshaid89 commited on
Commit
5d3977e
1 Parent(s): b58260f

Perfomed deep copy of image and drawing on copy of image instead of original image

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -56,6 +56,7 @@ def findThreshold(model_name, distance_metric):
56
  threshold = findThreshold(model_name , "cosine")
57
 
58
  def predict_image(image):
 
59
  if debug:
60
  print("1")
61
  # getting face embeddings from database
@@ -92,19 +93,20 @@ def predict_image(image):
92
 
93
  identities.append({"name":name , "facial_area":target_embedding_obj["facial_area"]})
94
 
 
95
  for identity in identities:
96
  # Draw the rectangle on the image
97
  x = identity["facial_area"]["x"]
98
  y = identity["facial_area"]["y"]
99
  w = identity["facial_area"]["w"]
100
  h = identity["facial_area"]["h"]
101
- cv2.rectangle(image, (x,y), (x+w,y+h), (0, 0, 255), 2)
102
 
103
  # Define the text position
104
  text_position = (x, y+h+30)
105
 
106
  # Add the text to the image
107
- cv2.putText(image, identity["name"], text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255,0 ), 2)
108
  return image
109
 
110
 
 
56
  threshold = findThreshold(model_name , "cosine")
57
 
58
  def predict_image(image):
59
+ original_image = np.copy(image)
60
  if debug:
61
  print("1")
62
  # getting face embeddings from database
 
93
 
94
  identities.append({"name":name , "facial_area":target_embedding_obj["facial_area"]})
95
 
96
+ output_img = np.copy(original_image)
97
  for identity in identities:
98
  # Draw the rectangle on the image
99
  x = identity["facial_area"]["x"]
100
  y = identity["facial_area"]["y"]
101
  w = identity["facial_area"]["w"]
102
  h = identity["facial_area"]["h"]
103
+ cv2.rectangle(output_img, (x,y), (x+w,y+h), (0, 0, 255), 2)
104
 
105
  # Define the text position
106
  text_position = (x, y+h+30)
107
 
108
  # Add the text to the image
109
+ cv2.putText(output_img identity["name"], text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255,0 ), 2)
110
  return image
111
 
112