我在python https://github.com/ageitgey/face_recognition
中探索face_recognition目前,我将face_encoding存储在一个字符串中。你可以看到我在字符串数组中如何转换,以便我可以将它保存在数据库中。
unknown_image = face_recognition.load_image_file("biden.jpg")
face_location_unknown = face_recognition.face_locations(unknown_image)
unknown_encoding = face_recognition.face_encodings(unknown_image, face_location_unknown)[0]
#conversion to string
unknown_encoding_string = "%s" % unknown_encoding
face_unknown_encoding_string = re.sub('\s+', ', ', unknown_encoding_string[1:-1])
“face_unknown_encoding_string”是这样的:
"-0.127419,0.0709146,0.0794749,-0.0321613,-0.0159098,0.00918037,-0.0360131,-0.0601268,0.0995623,-0.106627,0.253107,-0.00910004,-0.236208,-0.164839,0.0281254,0.173948,-0.157076,-0.099059,-0.0318014,-0.0617558,0.0104656,-0.00391768,0.0300188,0.082264,-0.116754,-0.42047,-0.112592,-0.124656,-0.0288262,-0.0780776,-0.0982438,0.0630722,-0.158208,-0.00986074,-0.044616,0.0979513,0.00402067,-7.38486e-05,0.140721,0.0392284,-0.180724,0.011891,0.000132522,0.247319,0.166832,0.0565608,0.022775,-0.0209147,0.040387,-0.172158,0.087646,0.134213,0.0793414,0.0392115,0.00153742,-0.118472,-0.0423868,0.0155273,-0.114884,0.0150463,-0.0130648,-0.136907,-0.0396041,-0.0299826,0.192542,0.107253,-0.102995,-0.147908,0.133909,-0.149223,-0.0397335,0.046862,-0.158645,-0.165123,-0.318725,0.13189,0.36383,0.134758,-0.162269,0.0299262,-0.12019,-0.0473435,0.0974606,0.13637,-0.0189891,0.00880722,-0.0928411,0.063979,0.139967,-0.0451124,-0.0430897,0.214811,-0.0380436,0.131413,0.0137761,0.0366569,-0.0442467,0.0497605,-0.0790947,0.00948556,0.0879658,-0.0556417,0.00738802,0.0854838,-0.15242,0.0731073,0.0232722,0.00448165,0.0829161,0.0995341,-0.163955,-0.143655,0.125336,-0.239622,0.174127,0.243117,0.0262358,0.122618,0.137583,0.109123,-0.00857285,-0.074666,-0.184109,0.00498615,0.131001,0.0170561,0.0319808,0.0229446,",
问题是如何转换此
face_unknown_encoding_string
回到与“unknown_encoding”相同的编码格式?
原因是我现在想要使用“compare_faces”进行比较
答案 0 :(得分:1)
该评论者没用。
我有一个非常类似的问题,我需要将一堆序列化的面部编码与一个新的面部编码进行比较,以查看它是否是同一个人,从而解决:
face_recognition.compare_faces(np.array(json.loads(person.face_encodings)), np.array(json.loads(unrecognized_rectangle.face_encoding)))