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

天津品牌网站建设公司做网站需要记哪些代码

天津品牌网站建设公司,做网站需要记哪些代码,网站建设要做固定资产吗,网站备案法律法规dlib人脸关键点绘制及微笑测试 目录 dlib人脸关键点绘制及微笑测试1 dlib人脸关键点1.1 dlib1.2 人脸关键点检测1.3 检测模型1.4 凸包1.5 笑容检测1.6 函数 2 人脸检测代码2.1 关键点绘制2.2 关键点连线2.3 微笑检测 1 dlib人脸关键点 1.1 dlib dlib 是一个强大的机器学习库&a…

dlib人脸关键点绘制及微笑测试

目录

  • dlib人脸关键点绘制及微笑测试
    • 1 dlib人脸关键点
      • 1.1 dlib
      • 1.2 人脸关键点检测
      • 1.3 检测模型
      • 1.4 凸包
      • 1.5 笑容检测
      • 1.6 函数
    • 2 人脸检测代码
      • 2.1 关键点绘制
      • 2.2 关键点连线
      • 2.3 微笑检测

1 dlib人脸关键点


1.1 dlib

dlib 是一个强大的机器学习库,广泛用于人脸检测和人脸关键点检测。它提供了一个预训练的 68 点人脸关键点检测模型,可以准确地定位人脸的各个部位(如眼睛、鼻子、嘴巴等)

1.2 人脸关键点检测

dlib 的 68 点人脸关键点检测模型基于 HOG(Histogram of Oriented Gradients)特征和线性分类器,结合了形状预测算法。它可以检测人脸的以下区域:
下巴(0-16)
右眉毛(17-21)
左眉毛(22-26)
鼻子(27-35)
右眼(36-41)
左眼(42-47)
嘴巴(48-67)

在这里插入图片描述

1.3 检测模型

dlib 提供了一个预训练的 68 点人脸关键点检测模型,可以从以下链接下载:
https://github.com/davisking/dlib-models/blob/master/shape_predictor_68_face_landmarks.dat.bz2/

1.4 凸包

凸包(Convex Hull) 是计算几何中的一个重要概念,指的是在二维或更高维空间中,包含一组点的最小凸多边形或凸多面体。凸包在图像处理、计算机视觉、模式识别等领域有广泛应用,例如在人脸关键点检测中,可以用凸包来定义人脸区域的边界

1.5 笑容检测

定义了两个函数,MAR:衡量嘴巴的张开程度,
和MJR:衡量嘴巴宽度与下巴宽度的比例,
人脸关键点如上,当微笑时嘴巴长款和脸颊长度都会发生改变,通过两个函数进行比较检测,进行判断是否微笑

def MAR(shape):x = shape[50]y = shape[50].reshape(1,2)A = euclidean_distances(shape[50].reshape(1,2),shape[58].reshape(1,2))B = euclidean_distances(shape[51].reshape(1,2),shape[57].reshape(1,2))C = euclidean_distances(shape[52].reshape(1,2),shape[56].reshape(1,2))D = euclidean_distances(shape[48].reshape(1,2),shape[54].reshape(1,2))return ((A+B+C)/3)/Ddef MJR(shape):M = euclidean_distances(shape[48].reshape(1,2),shape[54].reshape(1,2))J = euclidean_distances(shape[3].reshape(1,2),shape[13].reshape(1,2))return M/J

1.6 函数

  • detector = dlib.get_frontal_face_detector()加载人脸检测器
  • predictor = dlib.shape_predictor(‘shape_predictor_68_face_landmarks.dat’) 关键点预测器
  • detector(gray, 1)检测人脸
    • gray检测的灰度图
    • 1 表示对图像进行上采样次数

2 人脸检测代码


2.1 关键点绘制

代码展示:

import cv2
import numpy as np
import dlibimg = cv2.imread('lyf.png')
detector = dlib.get_frontal_face_detector()
faces = detector(img,0)
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
for face in faces:shape = predictor(img,face)landmarks = np.array([[p.x,p.y] for p in shape.parts()])for idx,point in enumerate(landmarks):pos = [point[0],point[1]]cv2.circle(img,pos,2,color=(0,255,0),thickness=-1)cv2.putText(img,str(idx),pos,cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,0.4,(255,255,255),1,cv2.LINE_AA)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

运行结果:
在这里插入图片描述

2.2 关键点连线

代码展示:

import cv2
import numpy as np
import dlibdef drawLine(start,end):pts = shape[start:end]for l in  range(1,len(pts)):pta = tuple(pts[l-1])ptb = tuple(pts[l])cv2.line(img,pta,ptb,(0,255,0),1)def drawConvexHull(start,end):facial = shape[start:end+1]mouthHull = cv2.convexHull(facial)cv2.drawContours(img,[mouthHull],-1,(0,255,0),1)img = cv2.imread('lyf.png')
detector = dlib.get_frontal_face_detector()
faces = detector(img,0)
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
for face in faces:shape = predictor(img,face)shape = np.array([[p.x,p.y] for p in shape.parts()])drawConvexHull(36,41)drawConvexHull(42,47)drawConvexHull(48, 59)drawConvexHull(60, 67)drawLine(0,17)drawLine(17, 22)drawLine(22, 27)drawLine(27, 36)cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

运行结果:
在这里插入图片描述

2.3 微笑检测

代码展示:

import cv2
import numpy as np
import dlib
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
v = cv2.VideoCapture('jjy_dyx.mp4')
from sklearn.metrics.pairwise import euclidean_distances
from PIL import Image, ImageDraw, ImageFontdef cv2AddChineseText(img, text, position, textColor=(255, 255, 255), textSize=30):""" 向图片中添加中文 """if (isinstance(img, np.ndarray)):  # 判断是否OpenCV图片类型img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))#实现array到image的转换draw = ImageDraw.Draw(img)# 在img图片上创建一个绘图的对象# 字体的格式fontStyle = ImageFont.truetype("simsun.ttc", textSize, encoding="utf-8")draw.text(position, text, textColor, font=fontStyle) # 绘制文本return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)# 转换回OpenCV格式def MAR(shape):x = shape[50]y = shape[50].reshape(1,2)A = euclidean_distances(shape[50].reshape(1,2),shape[58].reshape(1,2))B = euclidean_distances(shape[51].reshape(1,2),shape[57].reshape(1,2))C = euclidean_distances(shape[52].reshape(1,2),shape[56].reshape(1,2))D = euclidean_distances(shape[48].reshape(1,2),shape[54].reshape(1,2))return ((A+B+C)/3)/Ddef MJR(shape):M = euclidean_distances(shape[48].reshape(1,2),shape[54].reshape(1,2))J = euclidean_distances(shape[3].reshape(1,2),shape[13].reshape(1,2))return M/Jwhile True:r,img = v.read()if not r:breakfaces = detector(img,0)for face in faces:shape = predictor(img,face)shape= np.array([[p.x,p.y] for p in shape.parts()])mar = MAR(shape)mjr =MJR(shape)result = '正常'print('mar:',mar,'mjr:',mjr)if mar>0.5:result = '大笑'elif mjr>0.4:result = '微笑'mouthHull = cv2.convexHull(shape[48:61])img = cv2AddChineseText(img,result,mouthHull[0,0],1)cv2.drawContours(img,[mouthHull],-1,(0,255,0),1)cv2.imshow('img', img)key = cv2.waitKey(1)if key == 32:break
v.release()
cv2.waitKey(0)
cv2.destroyAllWindows()

运行结果:
在这里插入图片描述


文章转载自:

http://6DQeHH2R.ywtbk.cn
http://o8lmlPkS.ywtbk.cn
http://K2MBK11T.ywtbk.cn
http://GUmS86Jr.ywtbk.cn
http://5Z3vcKKx.ywtbk.cn
http://vZVDS0xN.ywtbk.cn
http://ISseRc25.ywtbk.cn
http://k9W7EyfF.ywtbk.cn
http://VgbzN2YS.ywtbk.cn
http://6ClNX9QT.ywtbk.cn
http://P0UhHtSr.ywtbk.cn
http://h2BjWW8W.ywtbk.cn
http://GrNwxkBN.ywtbk.cn
http://LZCh2tz2.ywtbk.cn
http://LxhMzpq7.ywtbk.cn
http://sSYjuVuX.ywtbk.cn
http://L0HvGM4g.ywtbk.cn
http://KoRYTIB0.ywtbk.cn
http://SwQ2hCgg.ywtbk.cn
http://KronuHtC.ywtbk.cn
http://b0wIFQoH.ywtbk.cn
http://rxUCNAFK.ywtbk.cn
http://F9Ny3Ua4.ywtbk.cn
http://GUOEEtoa.ywtbk.cn
http://HDWTIVdX.ywtbk.cn
http://dmJAVj3V.ywtbk.cn
http://u81D4bSu.ywtbk.cn
http://hTYjOvLh.ywtbk.cn
http://sV5gPA1B.ywtbk.cn
http://1Yu4KIZ8.ywtbk.cn
http://www.dtcms.com/wzjs/717323.html

相关文章:

  • 做手机网站公司手机网站的价值
  • 做直播网站需要学什么软件有哪些wordpress启动ssl
  • 网站开发app重庆网站备案最快几天
  • 为什么需要建设网站百度网页入口
  • 防做电脑租赁网站南通城乡建设局网站首页
  • 如何自学网站建设书籍淘客二级域名网站免费建设
  • 网站设计的公司logo网络设计目标
  • 宁波网站制作出售销售平台是什么意思
  • 个人免费展示网站镇江百度网站
  • 扬州市住房和城乡建设局网站计算机应用技术网站开发基础知识
  • 建设带数据搜索的网站网站可信度验证
  • 京东网站设计分析佛山新网站建设效果
  • 中国品牌网站设计企业网络营销站点的功能有哪些
  • 灵璧做网站公司响应式网站 手机版
  • 如何做财经网站wordpress页面模板下载地址
  • 微信小程序制作免费轻站平台杭州网站备案要多久
  • 美工素材网站有哪些石家庄房产信息网站
  • 长沙低价网站建设农村自建房设计
  • jsp网站开发的教材免费招聘网站建设
  • 做暧嗳网站dedecms织梦
  • 律师网站素材西安做网站哪家便宜
  • 中小型网站建设市场解读wordpress php代码
  • 网站上传教程建立一个网站
  • 高性能wordpress杭州百度百家号seo优化排名
  • 福州全网网站建设做网站建设哪家公司好
  • 黄山网站开发wordpress 多站点 主站点
  • 哈尔滨住房建设发展集团网站合肥建设局
  • 中国三大门户网站是哪三个做商品抬价是什么兼职网站
  • 龙岗同乐社区网站建设静态网址
  • 湖南建立网站营销策划免费注册电子邮件地址