Ejemplo n.º 1
0
 def swap(self, image_fd, dataset, threshold=2.0, max_size=(1024,1024)):
     target = faceswap.load_image(image_fd, max_size=max_size)
     face_info = faceswap.extract_face_infos(target)
     for info in face_info:
         score, db_image_data = self.find(info.imghash, dataset)
         if score < threshold:
             db_image = faceswap.load_image(open(db_image_data['image_path']))
             target = transform.faceswap(db_image, db_image_data, target, info)
     return target
Ejemplo n.º 2
0
 def _parse_image(self, image, basename, db, image_path):
     try:
         os.makedirs(os.path.join("./database/", db, 'cache'))
     except:
         pass
     for i, info in enumerate(faceswap.extract_face_infos(image)):
         print "\t\tAdding face: ", i
         file_base = "./database/{}/cache/{}_{}".format(db, basename, i)
         data = {
             "imghash": info.imghash,
             "landmarks": info.landmarks,
             "face_box": info.face_box,
             "image_path": image_path,
             "id": image_path + str(i)
         }
         cPickle.dump(data, open(file_base + ".pkl", 'w+'))
         yield data['id'], data