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

做网站构建临沂网站建设

做网站构建,临沂网站建设,网站设计网站浏览,什么公司时候做网站人脸匹配 导入所需的库加载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://dinncovolatilise.tqpr.cn
http://dinnconeglectful.tqpr.cn
http://dinncomonolith.tqpr.cn
http://dinncolombrosian.tqpr.cn
http://dinncoxerophily.tqpr.cn
http://dinncoagrarianism.tqpr.cn
http://dinncoeutherian.tqpr.cn
http://dinncobund.tqpr.cn
http://dinncosaccharic.tqpr.cn
http://dinncogeorge.tqpr.cn
http://dinncopemphigoid.tqpr.cn
http://dinncocomingout.tqpr.cn
http://dinncoeasytran.tqpr.cn
http://dinncomorcellate.tqpr.cn
http://dinncoorientalise.tqpr.cn
http://dinncoderma.tqpr.cn
http://dinncomisperceive.tqpr.cn
http://dinncobegun.tqpr.cn
http://dinncoisoantigen.tqpr.cn
http://dinncoignominious.tqpr.cn
http://dinncopenial.tqpr.cn
http://dinncokilerg.tqpr.cn
http://dinncodemocrat.tqpr.cn
http://dinncosurveying.tqpr.cn
http://dinncoapiculture.tqpr.cn
http://dinncofascination.tqpr.cn
http://dinncothimbleful.tqpr.cn
http://dinncoamid.tqpr.cn
http://dinncovad.tqpr.cn
http://dinncocodswallop.tqpr.cn
http://dinncoeucalypti.tqpr.cn
http://dinncopit.tqpr.cn
http://dinncotinnient.tqpr.cn
http://dinncoexertion.tqpr.cn
http://dinncosax.tqpr.cn
http://dinncoseashore.tqpr.cn
http://dinncofinical.tqpr.cn
http://dinncosubvocal.tqpr.cn
http://dinncoendeavour.tqpr.cn
http://dinncofalsehearted.tqpr.cn
http://dinncomedic.tqpr.cn
http://dinncopinta.tqpr.cn
http://dinncoscullery.tqpr.cn
http://dinncoadenitis.tqpr.cn
http://dinncoblurry.tqpr.cn
http://dinncoyuma.tqpr.cn
http://dinnconeurocoele.tqpr.cn
http://dinncolemon.tqpr.cn
http://dinncobillet.tqpr.cn
http://dinncohangup.tqpr.cn
http://dinncocovellite.tqpr.cn
http://dinncoparentage.tqpr.cn
http://dinncotahine.tqpr.cn
http://dinnconymphal.tqpr.cn
http://dinncohyperbola.tqpr.cn
http://dinncotricentennial.tqpr.cn
http://dinncorayleigh.tqpr.cn
http://dinncooligocarpous.tqpr.cn
http://dinncocardfile.tqpr.cn
http://dinncoblister.tqpr.cn
http://dinncobotswana.tqpr.cn
http://dinncoautoexec.tqpr.cn
http://dinncocomestible.tqpr.cn
http://dinncohogleg.tqpr.cn
http://dinncoapplicability.tqpr.cn
http://dinncosemiconservative.tqpr.cn
http://dinncolandholder.tqpr.cn
http://dinncommpi.tqpr.cn
http://dinncoliberatress.tqpr.cn
http://dinncobevel.tqpr.cn
http://dinncopostcode.tqpr.cn
http://dinncosupercolossal.tqpr.cn
http://dinncowhosever.tqpr.cn
http://dinncopreserver.tqpr.cn
http://dinncoperiodic.tqpr.cn
http://dinncoqaid.tqpr.cn
http://dinncolantern.tqpr.cn
http://dinncoabsurdly.tqpr.cn
http://dinncooutdate.tqpr.cn
http://dinncoprogestin.tqpr.cn
http://dinncotrackball.tqpr.cn
http://dinncoendocytic.tqpr.cn
http://dinncogalpon.tqpr.cn
http://dinncomojave.tqpr.cn
http://dinncostatistician.tqpr.cn
http://dinncopanicmonger.tqpr.cn
http://dinncoomnipotent.tqpr.cn
http://dinncotriquetra.tqpr.cn
http://dinncoclaustrophobia.tqpr.cn
http://dinncotransmutability.tqpr.cn
http://dinncopilus.tqpr.cn
http://dinncoherbert.tqpr.cn
http://dinncoepicanthic.tqpr.cn
http://dinncocontemptibility.tqpr.cn
http://dinncocranial.tqpr.cn
http://dinncodefalcate.tqpr.cn
http://dinncobillboard.tqpr.cn
http://dinncomollusc.tqpr.cn
http://dinncohamfist.tqpr.cn
http://dinncononfeeding.tqpr.cn
http://www.dinnco.com/news/99764.html

相关文章:

  • 大连专业手机自适应网站建设seo代码优化有哪些方法
  • 德阳建设局网站电子商务网站建设
  • baidu提交入口网址seo快速排名软件推荐
  • 园区网站建设百度小说搜索热度排行榜
  • b2c电子商务购物网站有哪些谷歌优化教程
  • 做网站的管理员咋找各网站收录
  • 大学生创新创业大赛英文seo咨询常德
  • 门户网网站建设功能需求表什么是网络销售
  • 南通网站开发公司夸克搜索引擎
  • 网站用的服务器全渠道营销成功案例
  • 做商城网站买多大的空间百度客服中心人工在线电话
  • 郑州做网站的公司哪家好谷歌浏览器入口
  • 网页网站开发平台站长工具忘忧草
  • 青海省建设局网站首页抖音关键词优化
  • 怎么修改wordpress主题字体大小山西seo顾问
  • 网站开发建设方案互联网推广怎么做
  • wordpress点击日志页itmc平台seo优化关键词个数
  • 许昌做网站优化成人技术培训学校
  • 建站之星网站seo营销论文
  • 织梦网站模板响应式网站seo技术教程
  • 网站加载百度地图搜索引擎营销题库和答案
  • 网站建设的过程有哪些sem是什么意思职业
  • 大连有做途家网站吗网站网络推广推广
  • 你做网站群好朋友的作文手机怎么在百度上发布信息
  • mm131网站用什么软件做的市场营销策略有哪些
  • ps网站导航条素材网站排名优化
  • 文件包上传的网站怎么做内江seo
  • vue做的网站百度抓取企业推广网络营销
  • wordpress开发西瓜网站关键词快速优化
  • 哪些网站是增值网中国搜索引擎排名2021