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

直播网站开发核心技术北京十大营销策划公司

直播网站开发核心技术,北京十大营销策划公司,能免费做婚礼邀请函的网站,营销网站建设服务文章内容: 1)人脸检测的5种方法 1. Haar cascade opencv 2. HOG Dlib 3. CNN Dlib 4. SSD 5. MTCNN 一。人脸检测的5种方法实现 1. Haar cascade opencv Haar是专门用来检测边缘特征的。基本流程如下: 第1步,读取图片 img …

文章内容:

1)人脸检测的5种方法

        1. Haar cascade + opencv

        2. HOG + Dlib

        3. CNN + Dlib

        4. SSD

        5. MTCNN

一。人脸检测的5种方法实现

 1. Haar cascade + opencv

        Haar是专门用来检测边缘特征的。基本流程如下:

第1步,读取图片

img = cv2.imread('./images/faces1.jpg')

第2步,将图片转化为灰度图片,因为Haar检测器识别的是灰度图片

img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

第3步,构造Haar检测器

face_detector = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_default.xml')

第4步,检测器开始检测人脸

detections = face_detector.detectMultiScale(img_gray)

第5步,迭代器解析

for(x,y,w,h)in detections:cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),5)

第6步,显示

plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))

第7步,参数调节

-- scaleFactor

        scaleFactor是用来调节检测人脸大小的范围的,举个例子scaleFactor = 1表示人脸检测范围从1开始检测,人脸离相机远,脸小,离相机近脸大,因此scaleFactor的取值能一定程度上影响识别的精度。

        但有时候不论怎么调节scaleFactor都会出现下述情况 ,此时需要minNeighbor调节人脸框的候选数量

 --minNeighbors

        minNeighbors指每个人脸框最小的候选数量,算法为了检测人脸,可能会在一个人物照片的多个地方去检测人脸,最后会识别出多个地方可能都是人脸,这时minNeighbors会对这些识别结果进行排序取出最可能是人脸的地方,试想一下,如果所有的方框都集中在某一个区域,那么是不是代表这个区域内是人脸的可能性更高,当然是这样,这个方框集中在某一个区域的数量就叫做人脸框的候选数量用minNeighbors表示,显然minNeighbors较大比较好,太大了会出现漏检。

 --minSize

        minSize表示最小人脸尺寸,maxSize表示最大人脸尺寸,这两个参数都是用来控制人脸大小的,如

detections = face_detector.detectMultiScale(img_gray,scaleFactor = 1.2,minNeighbors =7,minSize=(1,1))

2. HOG + Dlib

第1步,读取图片

img = cv2.imread('./images/faces2.jpg')
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))

第2步,构造HOG检测器,需要安装Dlib包(conda install -c conda-forge dlib)

import dlib
hog_face_detector = dlib.get_frontal_face_detector()

第3步,检测人脸

detections= hog_face_detector(img,1)#指的是scaleFactor=1

第4步,解析

for face in detections:x = face.left()y = face.top()r = face.right()b = face.bottom()cv2.rectangle(img,(x,y),(r,b),(0,255,0),5)

第5步,显示

plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))

3. CNN + Dlib

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi'] = 200
img = cv2.imread('./images/faces2.jpg')
import dlib
cnn_face_detector = dlib.cnn_face_detection_model_v1('./weights/mmod_human_face_detector.dat')
detections = cnn_face_detector(img,1)
for face in detections:x = face.rect.left()y = face.rect.top()r = face.rect.right()b = face.rect.bottom()c = face.confidencecv2.rectangle(img,(x,y),(r,b),(0,255,0),5)
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))

 4. SSD

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi']=200
img = cv2.imread('./images/faces2.jpg')
face_detector = cv2.dnn.readNetFromCaffe('./weights/deploy.prototxt.txt','./weights/res10_300x300_ssd_iter_140000.caffemodel')
img_height = img.shape[0]
img_width = img.shape[1]
img_resize = cv2.resize(img,(500,300))
img_blob = cv2.dnn.blobFromImage(img_resize,1.0,(500,300),(104.0, 177.0, 123.0))
face_detector.setInput(img_blob)
detections = face_detector.forward()
num_of_detections = detections.shape[2]
img_copy = img.copy()
for index in range(num_of_detections):detection_confidence = detections[0,0,index,2]if detection_confidence>0.15:locations = detections[0,0,index,3:7] * np.array([img_width,img_height,img_width,img_height])lx,ly,rx,ry  = locations.astype('int')cv2.rectangle(img_copy,(lx,ly),(rx,ry),(0,255,0),5)
plt.imshow(cv2.cvtColor(img_copy,cv2.COLOR_BGR2RGB))   

5. MTCNN

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi']=200img = cv2.imread('./images/faces2.jpg')
img_cvt = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
from mtcnn.mtcnn import MTCNN
face_detetor = MTCNN()
detections = face_detetor.detect_faces(img_cvt)
for face in detections:(x, y, w, h) = face['box']cv2.rectangle(img_cvt, (x, y), (x + w, y + h), (0,255,0), 5)
plt.imshow(img_cvt)

import cv2
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi']=200
img = cv2.imread('./images/test.jpg')
img_cvt = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
from mtcnn.mtcnn import MTCNN
face_detetor = MTCNN()
detections = face_detetor.detect_faces(img_cvt)
for face in detections:(x, y, w, h) = face['box']cv2.rectangle(img_cvt, (x, y), (x + w, y + h), (0,255,0), 5)
plt.imshow(img_cvt)

 5种人脸检测方式对比

视频流人脸检测 :

        1.构造haar人脸检测器

        2.获取视频流

        3.检测每一帧画面

        4.画人脸框并显示

import cv2
import numpy as np
cap = cv2.VideoCapture(0)
haar_face_detector = cv2.CascadeClassifier('./cascades/haarcascade_frontalface_default.xml')
while True:ret,frame = cap.read()fram = cv2.flip(frame,1)frame_gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)detection = haar_face_detector.detectMultiScale(frame_gray,minNeighbors=5)for(x,y,w,h) in detection:cv2.rectangle(fram,(x,y),(x+w,y+h),(0,255,0),5)cv2.imshow('Demo',fram)if cv2.waitKey(10) & 0xff == ord('q'):break
cap.release()
cv2.destoryAllWindows()

http://www.hkea.cn/news/552998/

相关文章:

  • 做生存分析的网站有哪些专业的网站优化公司
  • 网站双倍浮动百度联盟app
  • 北京网站设计确保代码符合w3c广州网络营销的推广
  • 做网站实名认证有什么用百度移动端模拟点击排名
  • 知更鸟wordpress 怎样沈阳百度seo关键词优化排名
  • 携程网站模板互联网营销策略有哪些
  • 做网站内链什么意思上海排名优化seobwyseo
  • 四川做直销会员网站百度网盘帐号登录入口
  • 做百度竞价对网站有无要求网站推广排名服务
  • 建设工程合同包括成都网站改版优化
  • 深圳不加班的互联网公司整站seo优化
  • 中国做的很好的食品网站肇庆疫情最新消息
  • 做时时彩网站微信seo关键词有话要多少钱
  • 陇南市建设局网站商务软文写作
  • 做学术研究的网站营销方案怎么写?
  • 专业网站设计公司有哪些秒收录关键词代发
  • 织梦网站模板源码下载真实有效的优化排名
  • 网站建设过程中什么最重要磁力链bt磁力天堂
  • html5企业网站案例鹤壁搜索引擎优化
  • 网站建设平台简介链接交换平台
  • 照片展示网站模板宁波seo咨询
  • 奉贤建设机械网站制作长沙网址seo
  • 上海企业网站模板建站常用的网络推广方法
  • 大连零基础网站建设教学培训济南seo优化公司
  • html 做网站案例简单网站推广建设
  • 践行新使命忠诚保大庆网站建设线上广告
  • 定制网站建设服务商商家联盟营销方案
  • 集团官网建设公司外贸seo推广公司
  • 佛山新网站制作平台网站诊断工具
  • 做PPT的网站canvawhois查询