Anuj-Panthri commited on
Commit
1bc858f
·
1 Parent(s): 5fdba97

fixed rescaling objs_found in api face_recognize route

Browse files
Files changed (2) hide show
  1. app/api/routes.py +7 -8
  2. face_recognition/helper.py +14 -4
app/api/routes.py CHANGED
@@ -224,26 +224,25 @@ def face_recognition(username):
224
  print(faces[i],":",db_faces_features[i].shape)
225
 
226
 
227
- img,objs_found=face_detector.predict(image)
228
- h,w=img.shape[:2]
 
 
229
  tree=fr_helper.objs_found_to_xml("test.jpg",w,h,objs_found)
230
 
231
  # face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="avg",recognition_mode="repeat")
232
  face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
233
 
234
  if len(faces)>0:
235
- tree=face_recognizer.predict(img,tree)
236
 
237
 
238
- # print(objs_found[0])
239
-
240
 
241
- pred_img=fr_helper.show_pred_image(tree,img)
242
  pred_img=image_to_base64(pred_img)
243
  objs_found=fr_helper.xml_to_objs_found(tree) # everything is okay till here
244
 
245
- objs_found=face_detector.square_preprocessing.rescale(objs_found) #rescale coordinates to original image's resolution
246
- # print(objs_found[0])
247
 
248
  all_crops=fd_get_crops(image,objs_found)
249
  all_crops_base64=[]
 
224
  print(faces[i],":",db_faces_features[i].shape)
225
 
226
 
227
+ _,objs_found=face_detector.predict(image)
228
+ objs_found=face_detector.square_preprocessing.rescale(objs_found) #rescale coordinates to original image's resolution
229
+ h,w=image.shape[:2]
230
+
231
  tree=fr_helper.objs_found_to_xml("test.jpg",w,h,objs_found)
232
 
233
  # face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="avg",recognition_mode="repeat")
234
  face_recognizer.set_face_db_and_mode(faces=faces,db_faces_features=db_faces_features,distance_mode="best",recognition_mode="repeat")
235
 
236
  if len(faces)>0:
237
+ tree=face_recognizer.predict(image,tree)
238
 
239
 
 
 
240
 
241
+ pred_img=fr_helper.show_pred_image(tree,image)
242
  pred_img=image_to_base64(pred_img)
243
  objs_found=fr_helper.xml_to_objs_found(tree) # everything is okay till here
244
 
245
+
 
246
 
247
  all_crops=fd_get_crops(image,objs_found)
248
  all_crops_base64=[]
face_recognition/helper.py CHANGED
@@ -53,6 +53,15 @@ def xml_to_objs_found(tree):
53
 
54
 
55
  def objs_found_to_xml(test_img,w,h,objs_found):
 
 
 
 
 
 
 
 
 
56
  root=ET.Element("annotation")
57
 
58
  filename_tag=ET.Element("filename")
@@ -80,7 +89,7 @@ def objs_found_to_xml(test_img,w,h,objs_found):
80
 
81
  # add all objects
82
  for obj_found in objs_found:
83
- obj_found['xywh']=np.array(obj_found['xywh'])*w
84
 
85
  obj_tag=ET.Element("object")
86
  name_tag=ET.Element("name")
@@ -97,8 +106,6 @@ def objs_found_to_xml(test_img,w,h,objs_found):
97
  ymax_tag=ET.Element("ymax")
98
  ymax_tag.text=str(int(obj_found['xywh'][1]+obj_found['xywh'][3]))
99
 
100
- obj_found['xywh']=np.array(obj_found['xywh'])/w
101
-
102
  bndbox_tag.append(xmin_tag)
103
  bndbox_tag.append(ymin_tag)
104
  bndbox_tag.append(xmax_tag)
@@ -112,4 +119,7 @@ def objs_found_to_xml(test_img,w,h,objs_found):
112
  # with open(xml_file_path,"wb") as f:
113
  # xml.write(f)
114
 
115
- return xml
 
 
 
 
53
 
54
 
55
  def objs_found_to_xml(test_img,w,h,objs_found):
56
+
57
+ def rescale(obj_found,w,h):
58
+ # xywh
59
+ obj_found[0]*=w
60
+ obj_found[1]*=h
61
+ obj_found[2]*=w
62
+ obj_found[3]*=h
63
+ return obj_found
64
+
65
  root=ET.Element("annotation")
66
 
67
  filename_tag=ET.Element("filename")
 
89
 
90
  # add all objects
91
  for obj_found in objs_found:
92
+ obj_found['xywh']=rescale(obj_found['xywh'],w,h)
93
 
94
  obj_tag=ET.Element("object")
95
  name_tag=ET.Element("name")
 
106
  ymax_tag=ET.Element("ymax")
107
  ymax_tag.text=str(int(obj_found['xywh'][1]+obj_found['xywh'][3]))
108
 
 
 
109
  bndbox_tag.append(xmin_tag)
110
  bndbox_tag.append(ymin_tag)
111
  bndbox_tag.append(xmax_tag)
 
119
  # with open(xml_file_path,"wb") as f:
120
  # xml.write(f)
121
 
122
+ return xml
123
+
124
+
125
+