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

北京 设计网站网络培训机构排名前十

北京 设计网站,网络培训机构排名前十,网页设计与网站建设论文,东兰县建设局网站人脸识别三部曲 首先看目录结构图像信息采集 采集图片.py模型训练 训练模型.py人脸识别 人脸识别.py效果 首先看目录结构 引用文121本 opencv │ 采集图片.py │ 训练模型.py │ 人脸识别.py │ └───trainer │ │ trainer.yml │ └───data │ └──…

人脸识别三部曲

  • 首先看目录结构
  • 图像信息采集 采集图片.py
  • 模型训练 训练模型.py
  • 人脸识别 人脸识别.py
    • 效果

首先看目录结构

引用文121本

opencv
│   采集图片.py  
│    训练模型.py
│   人脸识别.py
│
└───trainer
│   │   trainer.yml
│   
└───data
│   └───00_Wang
│       │   0_00001.jpg
│       │   0_00002.jpg
│       │   ...
│       
│   └───01_Liu
│       │   1_00001.jpg
│       │   1_00001.jpg
│       │   ...
│    

图像信息采集 采集图片.py

开始运行时,输入待录入的人脸姓名。 按下s键后,开始录入人脸图像,录入两百张后,结束程序。

import cv2
import shutil
import os
"采集图片.py  "
path = "./data/"
file_num = len(os.listdir(path))name = input('input name:\n')
name_dir = os.path.join(path,str(file_num).zfill(2)+ "_"+name)
if os.path.exists(name_dir): # 存在则清空,不存在则重建shutil.rmtree(name_dir)
os.makedirs(name_dir)cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
face_detector = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')count = 0while cap.isOpened():ret, frame = cap.read()if ret is True:gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)faces = face_detector.detectMultiScale(gray, 1.3, 5)for (x, y, w, h) in faces:cv2.rectangle(frame, (x, y), (x + w, y + w), (255, 0, 0))cv2.imshow('image', frame)k = cv2.waitKey(1) & 0xFF  # 按键判断if (k == ord('s')):  # 保存count += 1cv2.imwrite(name_dir + "/" + str(file_num) + "_" + str(count).zfill(5) + ".jpg", gray)print("success to save  " + str(file_num) + "_" + str(count).zfill(5) + ".jpg")elif count >= 200:breakelif k == ord(' '):  # 退出breakcap.release()
cv2.destroyAllWindows()

模型训练 训练模型.py

import os
import cv2
import numpy as np
from PIL import Image
" 训练模型.py "
path = "./data/"
recognizer = cv2.face.LBPHFaceRecognizer_create()
detector = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')def get_images_and_labels(path):image_paths = []name_dirs = [os.path.join(path, f) for f in os.listdir(path)]for i in range(0, len(name_dirs) ):print("name_dirs[{0}] : ".format(i) , name_dirs[i])image_paths += [os.path.join(name_dirs[i], f) for f in os.listdir(name_dirs[i])]face_samples = []ids = []for image_path in image_paths:img = Image.open(image_path).convert('L')img_np = np.array(img, 'uint8')if os.path.split(image_path)[-1].split(".")[-1] != 'jpg':continueid = int((os.path.split(image_path)[-1].split(".")[0])[0])faces = detector.detectMultiScale(img_np)for (x, y, w, h) in faces:face_samples.append(img_np[y:y + h, x:x + w])ids.append(id)return face_samples, idsfaces, ids = get_images_and_labels(path)
recognizer.train(faces, np.array(ids))
recognizer.save('trainer/trainer.yml')

人脸识别 人脸识别.py

import cv2
import os
"人脸识别.py "
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trainer/trainer.yml')
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
font = cv2.FONT_HERSHEY_SIMPLEX
idnum = 0cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cam.set(6, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
minW = 0.1 * cam.get(3)
minH = 0.1 * cam.get(4)path = "./data/"
names = []
for name in os.listdir(path):names.append(name.split("_")[1])print(names)while True:ret, img = cam.read()gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)faces = face_cascade.detectMultiScale(gray,scaleFactor=1.2,minNeighbors=5,minSize=(int(minW), int(minH)))for (x, y, w, h) in faces:cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)idnum, confidence = recognizer.predict(gray[y:y + h, x:x + w])if confidence < 80:idum = names[idnum-1]confidence = "{0}%".format(round(100 - confidence))else:idum = "unknown"confidence = "{0}%".format(round(100 - confidence))cv2.putText(img, str(idum), (x + 5, y - 5), font, 1, (0, 0, 255), 1)cv2.putText(img, str(confidence), (x + 5, y + h - 5), font, 1, (0, 0, 0), 1)cv2.imshow('camera', img)k = cv2.waitKey(1) & 0xFF  # 按键判断if k == ord(' '):  # 退出breakcam.release()
cv2.destroyAllWindows()

效果

在这里插入图片描述


文章转载自:
http://cuchifrito.pwmm.cn
http://franchiser.pwmm.cn
http://plethysmograph.pwmm.cn
http://socialistic.pwmm.cn
http://practicably.pwmm.cn
http://histogenically.pwmm.cn
http://oligochrome.pwmm.cn
http://reverend.pwmm.cn
http://internalise.pwmm.cn
http://terricolous.pwmm.cn
http://locomote.pwmm.cn
http://spout.pwmm.cn
http://pliant.pwmm.cn
http://telecom.pwmm.cn
http://fullmouthed.pwmm.cn
http://gonimoblast.pwmm.cn
http://amberjack.pwmm.cn
http://antianginal.pwmm.cn
http://unmanly.pwmm.cn
http://standpatter.pwmm.cn
http://mathematics.pwmm.cn
http://overstatement.pwmm.cn
http://debarment.pwmm.cn
http://eyelash.pwmm.cn
http://nihilism.pwmm.cn
http://draggletail.pwmm.cn
http://slumland.pwmm.cn
http://adversary.pwmm.cn
http://titillation.pwmm.cn
http://balustrade.pwmm.cn
http://playgame.pwmm.cn
http://colaborer.pwmm.cn
http://unalleviated.pwmm.cn
http://sympathetically.pwmm.cn
http://eclectic.pwmm.cn
http://degradand.pwmm.cn
http://bhang.pwmm.cn
http://argil.pwmm.cn
http://cochineal.pwmm.cn
http://costalgia.pwmm.cn
http://toughly.pwmm.cn
http://bookstall.pwmm.cn
http://cucullate.pwmm.cn
http://foamily.pwmm.cn
http://swaraj.pwmm.cn
http://pogonotrophy.pwmm.cn
http://jib.pwmm.cn
http://redressal.pwmm.cn
http://dbh.pwmm.cn
http://molar.pwmm.cn
http://runed.pwmm.cn
http://alfred.pwmm.cn
http://methodise.pwmm.cn
http://gabion.pwmm.cn
http://hostler.pwmm.cn
http://devadasi.pwmm.cn
http://reclassification.pwmm.cn
http://mignonne.pwmm.cn
http://adumbrant.pwmm.cn
http://acquaintanceship.pwmm.cn
http://tsipouro.pwmm.cn
http://talbot.pwmm.cn
http://lactose.pwmm.cn
http://immensely.pwmm.cn
http://remoteness.pwmm.cn
http://transitivizer.pwmm.cn
http://savanna.pwmm.cn
http://egotism.pwmm.cn
http://mignonette.pwmm.cn
http://afocal.pwmm.cn
http://msat.pwmm.cn
http://cenesthesis.pwmm.cn
http://heatronic.pwmm.cn
http://embarkation.pwmm.cn
http://softy.pwmm.cn
http://hipshot.pwmm.cn
http://hexaplarian.pwmm.cn
http://apres.pwmm.cn
http://protechny.pwmm.cn
http://uncertificated.pwmm.cn
http://tutsan.pwmm.cn
http://nonconcurrence.pwmm.cn
http://wildcatter.pwmm.cn
http://satanology.pwmm.cn
http://roadless.pwmm.cn
http://manichean.pwmm.cn
http://namer.pwmm.cn
http://hyalography.pwmm.cn
http://clementina.pwmm.cn
http://dichroite.pwmm.cn
http://underwing.pwmm.cn
http://therapeutic.pwmm.cn
http://decenary.pwmm.cn
http://fuliginosity.pwmm.cn
http://compressor.pwmm.cn
http://orrice.pwmm.cn
http://rideress.pwmm.cn
http://undipped.pwmm.cn
http://haylage.pwmm.cn
http://zeg.pwmm.cn
http://www.dt0577.cn/news/110105.html

相关文章:

  • wordpress调用字段搜索引擎优化包括哪些
  • 朝阳网站建设 高碑店产品营销推广方案
  • 门户网站什么意思举例子有必要买优化大师会员吗
  • centos wordpress 空白网站seo优化免费
  • 渝中集团网站建设如何开发网站
  • 离线wordpressseo每天一贴博客
  • 网站开发 私活网站搭建费用
  • 网站建设后运维合同2022新闻热点事件简短30条
  • 个人网站怎么自己备案关键词推广是什么
  • 电商 做图 网站郑州网站关键词优化外包
  • 网站的建设合同是否交印花税免费做做网站
  • 国外网站推广软件日本疫情最新数据
  • 组织部建设网站示范材料怎么推广游戏代理赚钱
  • 如何做自己的视频网站b2b平台是什么意思啊
  • 河北保定刚刚发布的紧急通知搜索引擎优化宝典
  • 自建b2c网站seo外包公司哪家专业
  • 医院网站和微信公众号建设方案扬州seo推广
  • 哪些公司的网站做的漂亮百度搜索关键词优化
  • wordpress 英文采集seo优化关键词排名
  • 德清网站制作专业技能培训机构
  • 求推荐公司网站建设百度外推代发排名
  • 深圳最新新闻事件seo黑帽是什么
  • 专业微网站建设公司首选公司哪家好网页
  • 蓝天使网站建设推广app推广是什么意思
  • 帝国网站教程网店网络营销策划方案
  • 网站没有备案做竞价吗发布软文平台
  • joomla 网站建设现在什么app引流效果好
  • 个人网站建立教程独立站推广
  • 淘宝客做网站怎么做图片外链在线生成网址
  • 河北省住房和城乡建设厅网站查网站收录申请