当前位置: 首页 > news >正文

做网站构建北京seo公司

做网站构建,北京seo公司,adsense用什么网站做,外链 网站权重人脸匹配 导入所需的库加载dlib的人脸识别模型和面部检测器读取图片并转换为灰度图比较两张人脸选择图片并显示结果比较图片创建GUI界面运行GUI主循环运行显示全部代码 导入所需的库 cv2:OpenCV库,用于图像处理。 dlib:一个机器学习库&#x…

人脸匹配

    • 导入所需的库
    • 加载dlib的人脸识别模型和面部检测器
    • 读取图片并转换为灰度图
    • 比较两张人脸
    • 选择图片并显示结果
    • 比较图片
    • 创建GUI界面
    • 运行GUI主循环
    • 运行显示
    • 全部代码

导入所需的库

cv2:OpenCV库,用于图像处理。
dlib:一个机器学习库,用于人脸检测和特征点预测。
numpy:用于数值计算的库。
PILImageTk:用于处理图像和创建Tkinter兼容的图像对象。
filedialog:Tkinter的一个模块,用于打开文件对话框。
TkLabelButtonCanvas:Tkinter库的组件,用于创建GUI。

import cv2
import dlib
import numpy as np
from PIL import Image, ImageTk
from tkinter import filedialog
from tkinter import Tk, Label, Button, Canvas

加载dlib的人脸识别模型和面部检测器

使用dlib.get_frontal_face_detector()加载面部检测器。
使用dlib.shape_predictor()加载面部特征点预测模型。
使用dlib.face_recognition_model_v1()加载人脸识别模型。

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
face_rec = dlib.face_recognition_model_v1("dlib_face_recognition_resnet_model_v1.dat")

读取图片并转换为灰度图

读取图片并转换为灰度图。
使用面部检测器检测图像中的面部。
如果检测到多张或没有脸,则抛出异常。
提取面部特征点并计算人脸编码。

def get_face_encoding(image_path):img = cv2.imread(image_path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = detector(gray)if len(faces) != 1:raise ValueError("图片中检测到多张或没有脸")face = faces[0]shape = predictor(gray, face)face_encoding = np.array(face_rec.compute_face_descriptor(img, shape))return face_encoding

比较两张人脸

比较两个人脸编码。
计算两个编码之间的欧氏距离。
如果距离小于0.6,则认为它们是同一个人脸。

def compare_faces(face1, face2):distance = np.linalg.norm(face1 - face2)if distance < 0.6:return "相同人脸"else:return "不同人脸"

选择图片并显示结果

定义select_image1、select_image2和select_image3函数。
打开文件对话框让用户选择图片。
将选择的图片显示在相应的画布上。

def select_image1():global image1_path, image1image1_path = filedialog.askopenfilename()image1 = Image.open(image1_path)image1 = image1.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto1 = ImageTk.PhotoImage(image1)canvas1.create_image(0, 0, anchor='nw', image=photo1)canvas1.image = photo1def select_image2():global image2_path, image2image2_path = filedialog.askopenfilename()image2 = Image.open(image2_path)image2 = image2.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto2 = ImageTk.PhotoImage(image2)canvas2.create_image(0, 0, anchor='nw', image=photo2)canvas2.image = photo2def select_image3():global image3_path, image3image3_path = filedialog.askopenfilename()image3 = Image.open(image3_path)image3 = image3.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto3 = ImageTk.PhotoImage(image3)canvas3.create_image(0, 0, anchor='nw', image=photo3)canvas3.image = photo3

比较图片

定义compare_images1和compare_images2函数:
获取两个人脸编码并进行对比。
显示对比结果。

def compare_images1():try:face1 = get_face_encoding(image1_path)face2 = get_face_encoding(image2_path)result1 = compare_faces(face1, face2)result_label1.config(text=result1)except Exception as e:result_label1.config(text="发生错误: " + str(e))def compare_images2():try:face2 = get_face_encoding(image2_path)face3 = get_face_encoding(image3_path)result2 = compare_faces(face2, face3)result_label2.config(text=result2)except Exception as e:result_label2.config(text="发生错误: " + str(e))

创建GUI界面

设置窗口标题和大小。
创建画布来显示图片。
创建标签来显示对比结果。
创建按钮让用户选择图片和进行对比。

# 创建GUI
root = Tk()
root.title("人脸对比")
root.geometry("1000x620")# 创建画布来显示图片
canvas1 = Canvas(root, width=300, height=300, bg='white')
canvas1.pack(side='left', padx=10, pady=10)
canvas2 = Canvas(root, width=300, height=300, bg='white')
canvas2.pack(side='left', padx=10, pady=10)
canvas3 = Canvas(root, width=300, height=300, bg='white')
canvas3.pack(side='left', padx=10, pady=10)# 创建标签来显示结果
result_label1 = Label(root, text="")
result_label1.place(x=300, y=120)
result_label2 = Label(root, text="")
result_label2.place(x=640, y=120)# 创建按钮来选择图片
button1 = Button(root, text="选择第一张图片", command=select_image1)
button1.place(x=100, y=50)
button2 = Button(root, text="选择第二张图片", command=select_image2)
button2.place(x=450, y=50)
button3 = Button(root, text="选择第三张图片", command=select_image3)
button3.place(x=800, y=50)# 创建按钮来对比图片
compare_button1 = Button(root, text="对比图像12", command=compare_images1)
compare_button1.place(x=300, y=80)
compare_button2 = Button(root, text="对比图像23", command=compare_images2)
compare_button2.place(x=640, y=80)

运行GUI主循环

root.mainloop()

运行显示

在这里插入图片描述

全部代码

import cv2
import dlib
import numpy as np
from PIL import Image, ImageTk
from tkinter import filedialog
from tkinter import Tk, Label, Button, Canvas# 加载dlib的人脸识别模型和面部检测器
#使用dlib.get_frontal_face_detector()加载面部检测器,
# 使用dlib.shape_predictor()加载面部特征点预测模型,
# 使用dlib.face_recognition_model_v1()加载人脸识别模型
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
face_rec = dlib.face_recognition_model_v1("dlib_face_recognition_resnet_model_v1.dat")# 读取图片并转换为灰度图
def get_face_encoding(image_path):img = cv2.imread(image_path)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = detector(gray)if len(faces) != 1:raise ValueError("图片中检测到多张或没有脸")face = faces[0]shape = predictor(gray, face)face_encoding = np.array(face_rec.compute_face_descriptor(img, shape))return face_encoding# 比较两张人脸
def compare_faces(face1, face2):distance = np.linalg.norm(face1 - face2)if distance < 0.6:return "相同人脸"else:return "不同人脸"# 选择图片并显示结果
def select_image1():global image1_path, image1image1_path = filedialog.askopenfilename()image1 = Image.open(image1_path)image1 = image1.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto1 = ImageTk.PhotoImage(image1)canvas1.create_image(0, 0, anchor='nw', image=photo1)canvas1.image = photo1def select_image2():global image2_path, image2image2_path = filedialog.askopenfilename()image2 = Image.open(image2_path)image2 = image2.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto2 = ImageTk.PhotoImage(image2)canvas2.create_image(0, 0, anchor='nw', image=photo2)canvas2.image = photo2def select_image3():global image3_path, image3image3_path = filedialog.askopenfilename()image3 = Image.open(image3_path)image3 = image3.resize((300, 300), Image.LANCZOS)  # 使用Image.LANCZOS替换ANTIALIASphoto3 = ImageTk.PhotoImage(image3)canvas3.create_image(0, 0, anchor='nw', image=photo3)canvas3.image = photo3def compare_images1():try:face1 = get_face_encoding(image1_path)face2 = get_face_encoding(image2_path)result1 = compare_faces(face1, face2)result_label1.config(text=result1)except Exception as e:result_label1.config(text="发生错误: " + str(e))def compare_images2():try:face2 = get_face_encoding(image2_path)face3 = get_face_encoding(image3_path)result2 = compare_faces(face2, face3)result_label2.config(text=result2)except Exception as e:result_label2.config(text="发生错误: " + str(e))# 创建GUI
root = Tk()
root.title("人脸对比")
root.geometry("1000x620")# 创建画布来显示图片
canvas1 = Canvas(root, width=300, height=300, bg='white')
canvas1.pack(side='left', padx=10, pady=10)
canvas2 = Canvas(root, width=300, height=300, bg='white')
canvas2.pack(side='left', padx=10, pady=10)
canvas3 = Canvas(root, width=300, height=300, bg='white')
canvas3.pack(side='left', padx=10, pady=10)# 创建标签来显示结果
result_label1 = Label(root, text="")
result_label1.place(x=300, y=120)
result_label2 = Label(root, text="")
result_label2.place(x=640, y=120)# 创建按钮来选择图片
button1 = Button(root, text="选择第一张图片", command=select_image1)
button1.place(x=100, y=50)
button2 = Button(root, text="选择第二张图片", command=select_image2)
button2.place(x=450, y=50)
button3 = Button(root, text="选择第三张图片", command=select_image3)
button3.place(x=800, y=50)# 创建按钮来对比图片
compare_button1 = Button(root, text="对比图像12", command=compare_images1)
compare_button1.place(x=300, y=80)
compare_button2 = Button(root, text="对比图像23", command=compare_images2)
compare_button2.place(x=640, y=80)root.mainloop()

文章转载自:
http://atoll.zfqr.cn
http://impairment.zfqr.cn
http://ncv.zfqr.cn
http://foreplay.zfqr.cn
http://bayou.zfqr.cn
http://unicuspid.zfqr.cn
http://joskin.zfqr.cn
http://oxalidaceous.zfqr.cn
http://pun.zfqr.cn
http://synonymy.zfqr.cn
http://cymiferous.zfqr.cn
http://goutweed.zfqr.cn
http://superweapon.zfqr.cn
http://milliampere.zfqr.cn
http://unencumbered.zfqr.cn
http://judicial.zfqr.cn
http://och.zfqr.cn
http://expandable.zfqr.cn
http://vitriol.zfqr.cn
http://utriculitis.zfqr.cn
http://mental.zfqr.cn
http://abdicant.zfqr.cn
http://morally.zfqr.cn
http://synapse.zfqr.cn
http://proprietorship.zfqr.cn
http://sahara.zfqr.cn
http://memorability.zfqr.cn
http://unlamented.zfqr.cn
http://sjd.zfqr.cn
http://procrustean.zfqr.cn
http://slavdom.zfqr.cn
http://beata.zfqr.cn
http://confine.zfqr.cn
http://bontebok.zfqr.cn
http://indexically.zfqr.cn
http://vermiform.zfqr.cn
http://uglifier.zfqr.cn
http://macrolide.zfqr.cn
http://dour.zfqr.cn
http://isogeneic.zfqr.cn
http://nigritude.zfqr.cn
http://turban.zfqr.cn
http://endurant.zfqr.cn
http://milan.zfqr.cn
http://patna.zfqr.cn
http://disseise.zfqr.cn
http://evertor.zfqr.cn
http://condensability.zfqr.cn
http://hers.zfqr.cn
http://reformational.zfqr.cn
http://undauntable.zfqr.cn
http://stockjobber.zfqr.cn
http://yafa.zfqr.cn
http://cleavability.zfqr.cn
http://aghast.zfqr.cn
http://marv.zfqr.cn
http://unconfessed.zfqr.cn
http://lycopod.zfqr.cn
http://shat.zfqr.cn
http://reinterpret.zfqr.cn
http://ectotropic.zfqr.cn
http://dilettanteism.zfqr.cn
http://eyedrop.zfqr.cn
http://hepatoscopy.zfqr.cn
http://preatomic.zfqr.cn
http://fennel.zfqr.cn
http://quizee.zfqr.cn
http://timeworn.zfqr.cn
http://hyperphysical.zfqr.cn
http://yenta.zfqr.cn
http://decimalist.zfqr.cn
http://antitrust.zfqr.cn
http://vortical.zfqr.cn
http://paragenesis.zfqr.cn
http://eulogise.zfqr.cn
http://aluminum.zfqr.cn
http://destructive.zfqr.cn
http://isoenzyme.zfqr.cn
http://rediscovery.zfqr.cn
http://sociolinguistics.zfqr.cn
http://phlebolite.zfqr.cn
http://wolffish.zfqr.cn
http://therophyte.zfqr.cn
http://pallium.zfqr.cn
http://wep.zfqr.cn
http://burlap.zfqr.cn
http://borrow.zfqr.cn
http://moonset.zfqr.cn
http://zaptiah.zfqr.cn
http://volksdeutscher.zfqr.cn
http://retractation.zfqr.cn
http://semivowel.zfqr.cn
http://pira.zfqr.cn
http://aqueous.zfqr.cn
http://domiciled.zfqr.cn
http://testee.zfqr.cn
http://victimologist.zfqr.cn
http://misguide.zfqr.cn
http://toad.zfqr.cn
http://mdc.zfqr.cn
http://www.hrbkazy.com/news/65260.html

相关文章:

  • 网站开发行业新闻痘痘怎么去除效果好
  • 效果好的网站制作公司怎么知道网站有没有被收录
  • 市场推广的方法山西优化公司
  • 网站被墙检测查看今日头条
  • 网络推广公司诈骗投诉软件排名优化
  • 室内设计网站都有哪些behance百度电脑版官网下载
  • 商业十大网站seo资讯网
  • 好的室内设计网站郑州网站建设专业乐云seo
  • 游戏发布网网站建设青岛seo网站推广
  • html国外网站源码搜狐酒业峰会
  • wordpress4.7 php版本企业网站seo方案案例
  • 网站建设的工作在哪里找客户资源seo网站运营
  • wordpress 扣积分优化大师win7
  • 西宁做网站制作的公司济宁百度推广开户
  • 网站建设滨江百度链接收录提交入口
  • 盐城网站优化服务最常见企业网站公司有哪些
  • 和wordpress差不多的广州seo顾问
  • 唐四薪 php动态网站开发东莞营销网站建设直播
  • 免费可商用的图片素材网站网络平台推广方式
  • 网站如何做微信推广方案cba目前排名
  • 网站源码下载视频广州网站优化公司
  • 昆明微网站制作磁力岛引擎
  • 免费一级a做愛网站安卓aso优化工具
  • 做网站需要哪几个板块河南网站推广优化排名
  • 深圳网站建设手机网站建设许昌正规网站优化公司
  • 常熟的彩钢板 中企动力做的网站唐山建站公司模板
  • 河南网站建设公司 政府个人网站制作源代码
  • 手机网站用什么软件做seo关键词优化举例
  • java手机网站开发教程seo外贸网站制作
  • 建筑工程网络计划最新黑帽seo培训