小言_互联网的博客

python比较两张图片并获取精准度

329人阅读  评论(0)

先安装依赖库dlib、face_recognition、cv2

下载wheel文件:

python3.6:

dlib-19.7.0-cp36-cp36m-win_amd64.whl: https://drfs.ctcontents.com/file/1445568/768652503/68cb5d/Python/dlib-19.7.0-cp36-cp36m-win_amd64.whl

python3.7:

dlib-19.17.99-cp37-cp37m-win_amd64.whl: https://drfs.ctcontents.com/file/1445568/768652504/b726a5/Python/dlib-19.17.99-cp37-cp37m-win_amd64.whl

python3.8:

dlib-19.19.0-cp38-cp38-win_amd64.whl.whl: https://drfs.ctcontents.com/file/1445568/768652508/77e657/Python/dlib-19.19.0-cp38-cp38-win_amd64.whl.whl

再使用pip安装face_recognition、cv2


   
  1. pip install opencv-python
  2. pip install face-recognition

比较两张图片


   
  1. import cv2
  2. import face_recognition
  3. def find_face_encodings(image_path):
  4. # reading image
  5. image = cv2.imread(image_path)
  6. # get face encodings from the image
  7. face_enc = face_recognition.face_encodings(image)
  8. # return face encodings
  9. return face_enc[0]
  10. # getting face encodings for first image
  11. image_1 = find_face_encodings("image_1.png")
  12. # getting face encodings for second image
  13. image_2 = find_face_encodings("image_2.png")
  14. # checking both images are same
  15. is_same = face_recognition.compare_faces([image_1], image_2)[0]
  16. print(f"Is Same: {is_same}")
  17. if is_same:
  18. # finding the distance level between images
  19. distance = face_recognition.face_distance([image_1], image_2)
  20. distance = round(distance[0] * 100)
  21. # calcuating accuracy level between images
  22. accuracy = 100 - round(distance)
  23. print("The images are same")
  24. print(f"Accuracy Level: {accuracy}%")
  25. else:
  26. print("The images are not same")

输出:

Is Same: True

The images are same

Accuracy Level: 70%


转载:https://blog.csdn.net/qq_38316655/article/details/128730999
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场