因为某些原因需要眨眼识别,看到这个第一个想到的就是python,但是没接触过这个语言,所以我先看的java的写法,发现挺少。于是开始下载python开始了下载各种软件的道路。。。

原网址

虽然开始是在CSDN上花45积分下载的,但是发现这只是国外大佬写的。在这里给出国外大佬的原网址,就不给CSDN的了(明明人家免费,还在CSDN上卖45积分(小声BB))。

https://www.pyimagesearch.com/2017/04/24/eye-blink-detection-opencv-python-dlib/

问题

原网址上相关配置已经很详细了。在这里我就写我自己碰到的坑。。。

主要是这些opencvnumpy,以及dlib库,scipy库

除了dlib库其他都是直接按照网上教程直接成功的。

在这就说一下这个安装吧,找了无数的方法。最后成功了,而且还是个超级简单的。。。

首先下载dlib-19.17.0-cp37-cp37m-win_amd64.whl我已经把这个文件放在了蓝奏云。

然后直接安装,在解压好的文件夹的cmd窗口输入下面的就可以了。

pip install 文件名.whl

这里就不配安装好的图了。

wink.py的代码贴出来(原文并没有中文,中文是我机翻的)

# Command line parameters
# python Wink.py --shape-predictor shape_predictor_68_face_landmarks.dat --video your videoname.mp4
# python Wink.py --shape-predictor shape_predictor_68_face_landmarks.dat# import the necessary packages
from scipy.spatial import distance as dist
from imutils.video import FileVideoStream
from imutils.video import VideoStream
from imutils import face_utils
import numpy as np
import argparse
import imutils
import time
import dlib
import cv2
import winsounddef eye_aspect_ratio(eye):# compute the euclidean distances between the two sets of vertical eye landmarks (x, y)-coordinates# 计算两组垂直眼界标(x,y)坐标之间的欧几里得距离A = dist.euclidean(eye[1], eye[5])B = dist.euclidean(eye[2], eye[4])# compute the euclidean distance between the horizontal eye landmark (x, y)-coordinates# 计算水平眼界标(x,y)坐标之间的欧几里得距离C = dist.euclidean(eye[0], eye[3])# compute the eye aspect ratio 计算眼睛长宽比ear = (A + B) / (2.0 * C)# return the eye aspect ratio 返回眼睛长宽比return ear# construct the argument parse and parse the arguments 构造参数解析并解析参数
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--shape-predictor", required=True,help="path to facial landmark predictor")
ap.add_argument("-v", "--video", type=str, default="",help="path to input video file")
args = vars(ap.parse_args())# define two constants, one for the eye aspect ratio to indicate
# blink and then a second constant for the number of consecutive frames the eye must be below the threshold
# 定义两个常数,一个常数表示眼睛的纵横比以指示眨眼,然后定义第二个常数表示眼睛的连续帧数必须低于阈值
EYE_AR_THRESH = 0.25
EYE_AR_CONSEC_FRAMES = 2# initialize the frame counters and the total number of blinks 初始化帧计数器和闪烁总数
COUNTER = 0
TOTAL = 0# initialize dlib's face detector (HOG-based) and then create the facial landmark predictor
# 初始化dlib的面部检测器(基于HOG),然后创建面部界标预测器
print("[INFO] loading facial landmark predictor...")
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(args["shape_predictor"])# grab the indexes of the facial landmarks for the left and right eye, respectively
# 分别获取左眼和右眼的面部标志的索引
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]# start the video stream thread 启动视频流线程
print("[INFO] starting video stream thread...")
# vs = FileVideoStream(args["video"]).start()
fileStream = True
vs = VideoStream(src=0).start()fileStream = False
time.sleep(1.0)# loop over frames from the video stream 循环播放视频流中的帧
while True:# if this is a file video stream, then we need to check if there any more frames left in the buffer to process# 如果这是文件视频流,那么我们需要检查缓冲区中是否还有剩余的帧要处理if fileStream and not vs.more():break# grab the frame from the threaded video file stream, resize it, and convert it# to grayscale channels)# 从线程视频文件流中抓取帧,调整其大小,然后将其转换为灰度通道)frame = vs.read()frame = imutils.resize(frame, width=450)gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)# detect faces in the grayscale frame 在灰度框中检测人脸rects = detector(gray, 0)# loop over the face detections 循环人脸检测for rect in rects:# determine the facial landmarks for the face region, then convert# the facial landmark (x, y)-coordinates to a NumPy array# 确定面部区域的面部界标,然后将面部界标(x,y)坐标转换为NumPy数组shape = predictor(gray, rect)shape = face_utils.shape_to_np(shape)# extract the left and right eye coordinates, then use the coordinates to compute the eye aspect ratio for both eyes# 提取左眼和右眼坐标,然后使用坐标计算两只眼睛的眼睛纵横比leftEye = shape[lStart:lEnd]rightEye = shape[rStart:rEnd]leftEAR = eye_aspect_ratio(leftEye)rightEAR = eye_aspect_ratio(rightEye)# average the eye aspect ratio together for both eyes 将两只眼睛的眼睛纵横比平均在一起ear = (leftEAR + rightEAR) / 2.0# compute the convex hull for the left and right eye, then visualize each of the eyes# 计算左眼和右眼的凸包,然后可视化每只眼睛leftEyeHull = cv2.convexHull(leftEye)rightEyeHull = cv2.convexHull(rightEye)cv2.drawContours(frame, [leftEyeHull], -1, (0, 255, 0), 1)cv2.drawContours(frame, [rightEyeHull], -1, (0, 255, 0), 1)# check to see if the eye aspect ratio is below the blink threshold, and if so, increment the blink frame counter# 检查眼睛宽高比是否低于眨眼阈值,如果是,则增加眨眼帧计数器if ear < EYE_AR_THRESH:COUNTER += 1# otherwise, the eye aspect ratio is not below the blink threshold# 否则,眼睛纵横比不低于眨眼阈值else:# if the eyes were closed for a sufficient number of then increment the total number of blinks# 如果闭上眼睛的次数足够多,则增加眨眼的总数if COUNTER >= EYE_AR_CONSEC_FRAMES:TOTAL += 1# reset the eye frame counter 重置眼框计数器COUNTER = 0# draw the total number of blinks on the frame along with the computed eye aspect ratio for the frame# 绘制帧上眨眼的总数以及计算出的帧的眼睛纵横比cv2.putText(frame, "Blinks: {}".format(TOTAL), (10, 30),cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)cv2.putText(frame, "EAR: {:.2f}".format(ear), (300, 30),cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)cv2.putText(frame, "COUNTER: {}".format(COUNTER), (140, 30),cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)# show the frame show the framecv2.imshow("Frame", frame)key = cv2.waitKey(1) & 0xFF# if the `q` key was pressed, break from the loopif key == ord("q"):break# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()

使用

python Wink.py --shape-predictor shape_predictor_68_face_landmarks.dat --video your videoname.mp4python Wink.py --shape-predictor shape_predictor_68_face_landmarks.dat

效果图

这个可以检测摄像头也可以检测视频里的,我都试过了可以,下面来个视频(周董的说好不哭的MV)的效果图(滑稽图)。

文章原网址:

使用OpenCV,Python和dlib进行眨眼检测

使用OpenCV,Python和dlib进行眨眼检测相关推荐

  1. 使用OpenCV,Python和dlib进行眨眼检测及计数

    前三篇博客学习了 windows10+Python3.7安装dlib库进行面部标志识别 python dlib实现面部标志识别 使用python,dlib,OpenCV提取眼睛,鼻子,嘴唇及下颌 这篇 ...

  2. python使用opencv_教你快速使用OpenCV/Python/dlib進行眨眼檢測識別!

    摘要: 影象識別的新思路:眼睛縱橫比,看看大牛如果用這種思路玩轉識別眨眼動作! 今天我們來使用面部標誌和OpenCV 檢測和計算視訊流中的眨眼次數.為了構建我們的眨眼檢測器,我們將計算一個稱為眼睛縱橫 ...

  3. python人脸识别毕业设计-Python基于Dlib的人脸识别系统的实现

    之前已经介绍过人脸识别的基础概念,以及基于opencv的实现方式,今天,我们使用dlib来提取128维的人脸嵌入,并使用k临近值方法来实现人脸识别. 人脸识别系统的实现流程与之前是一样的,只是这里我们 ...

  4. python pip安装第三方库老是报错_#python pip 安装dlib一直失败?#python安装dlib错误...

    #python pip 安装dlib一直失败?#python安装dlib错误 python dlib 教程2020-10-11 07:52:36人已围观 ubuntu里面怎么安装dlib 下面是在ub ...

  5. 美颜(磨皮,大眼)opencv python实现

    本文是利用opencv python 的美颜(磨皮,大眼)实现. 1 磨皮 1.1 导向滤波 磨皮使用的是导向滤波进行磨皮.关于导向滤波的介绍,可以看我的另一篇文章导向滤波与opencv python ...

  6. opencv python安装 centos_centos下安装opencv

    根据项目需要,安装opencv并提供给开发使用,并且使用opencv提供python3的API接口.虽然不知道是个啥,还是简单了解下. opencv是什么? OpenCV的全称是Open Source ...

  7. 基于Python,dlib实现人脸关键点检测

    @代码实现及安装过程 基于Python,dlib实现人脸关键点检测 dilb 在做人脸检测人脸识别方面用到比较多的.face_recognition就是基于dlib实现的. 这篇文章将使用Python ...

  8. OpenCV+python:Canny边缘检测算法

    1,边缘处理 图像边缘信息主要集中在高频段,通常说图像锐化或检测边缘,实质就是高频滤波.我们知道微分运算是求信号的变化率,具有加强高频分量的作用. 在空域运算中来说,对图像的锐化就是计算微分.由于数字 ...

  9. OpenCV Python在计算机视觉中的应用

    OpenCV Python教程 在这篇文章中,我们将使用Python中的OpenCv来涵盖计算机视觉的各个方面.OpenCV长期以来一直是软件开发的重要组成部分. 什么是计算机视觉? 我们考虑一个场景 ...

  10. python基于dlib的face landmarks

    python基于dlib的face landmarks python使用dlib进行人脸检测与人脸关键点标记 Dlib简介: 首先给大家介绍一下Dlib Dlib是一个跨平台的C++公共库,除了线程支 ...

最新文章

  1. 基于Virtual DOM与Diff DOM的测试代码生成
  2. 500页开放书搞定概率图建模,图灵奖得主Judea Pearl推荐(附链接)
  3. 算法 求子数组的最大和 C
  4. ThinkPHP中的视图二
  5. 阿里云物联网平台远程配置功能JAVA 示例参考
  6. FPGA复位激励编写(方法一)
  7. ultraedit教程java_Java开发工具配置UltraEdit基础教程
  8. 学好JAVA保终身_JAVA IO 学习
  9. 纯css实现div中未知尺寸图片的垂直居中
  10. windows消息处理机制和VB
  11. 网络学习(学堂在线)
  12. python turtle菜鸟教程_【读书】Django教程(菜鸟教程)
  13. ASP使用ASPupload组件上传多个文件
  14. 计算机安全排名,电脑安全卫士排行榜
  15. WinDbg 定位句柄泄漏问题
  16. 将整数翻译成英文(C++)
  17. Maya创建重力动力模型教程!
  18. GHHHG全球海岸线提取
  19. 信号完整性分析系列——1基本概念
  20. 2021年全球复合半导体收入大约1083.1百万美元,预计2028年达到1580.8百万美元

热门文章

  1. pygame初探:复刻小游戏《Flappy Bird》
  2. 个人笔记——消除无用符号·消除空产生式·消除单一产生式·消除左递归
  3. 30款常用的大数据分析工具推荐(最新)
  4. Unity(OpenGL)实现“阴阳师画符”、划线功能
  5. 苹果产品介绍合集(加广告语和官方介绍)第二版--由Apple_VM_Xiaoqie整理(微信,抖音同号)
  6. edge浏览器使用IE模式进行调试
  7. 中科探海的海底掩埋物三维实时成像声呐
  8. 【优先队列】Toda 2
  9. IE下载文件无法弹出下载框
  10. Excel学习笔记:P18-COUNTIFS函数与SUMIFS函数