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

先安装依赖库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

pip install opencv-python
pip install face-recognition

比较两张图片

import cv2
import face_recognition

def find_face_encodings(image_path):
    # reading image
    image = cv2.imread(image_path)
    
    # get face encodings from the image
    face_enc = face_recognition.face_encodings(image)
    
    # return face encodings
    return face_enc[0]

# getting face encodings for first image
image_1 = find_face_encodings("image_1.png")

# getting face encodings for second image
image_2  = find_face_encodings("image_2.png")

# checking both images are same
is_same = face_recognition.compare_faces([image_1], image_2)[0]
print(f"Is Same: {is_same}")
if is_same:
    # finding the distance level between images
    distance = face_recognition.face_distance([image_1], image_2)
    distance = round(distance[0] * 100)
    
    # calcuating accuracy level between images
    accuracy = 100 - round(distance)
    
    print("The images are same")
    print(f"Accuracy Level: {accuracy}%")
else:
    print("The images are not same")

输出:

Is Same: True

The images are same

Accuracy Level: 70%

  • 16
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值