首页 > 其他分享 >项目备份

项目备份

时间:2023-08-19 22:22:43浏览次数:29  
标签:eye 项目 备份 cv2 shape part coords time

import cv2
import dlib
import threading
import queue
import math
import time


start_time=time.time()   #初始化计数器

minute_ant=0

minute_cnt=0




def euclidean_distance(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
def detect_faces():
    global start_time, minute_ant, minute_cnt  # 引入全局变量
    ant = 0  # 初始化闭眼次数
    cnt=0 #嘴巴张开次数
    while True:
        ret, frame = capture.read()

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        



        faces = detector(gray, 1)

        avg_brightness = int(gray.mean())

        # 检查光线亮度,显示光线暗的提醒
        if avg_brightness < 30:
            cv2.putText(frame, "Light is too dim open Zero-dce", (10, 110), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
        for face in faces:
            cv2.rectangle(frame, (face.left(), face.top()), (face.right(), face.bottom()), (0, 255, 0), 2)
            shape = predictor(gray, face)
            # 左眼关键点坐标提取

            left_eye_coords = [(shape.part(i).x, shape.part(i).y) for i in range(36, 42)]
            # 右眼关键点坐标提取

            right_eye_coords = [(shape.part(i).x, shape.part(i).y) for i in range(42, 48)]
            # 嘴巴关键坐标提取

            mouth1x=shape.part(49).x
            mouth1y = shape.part(49).y
            mouth2x = shape.part(51).x
            mouth2y = shape.part(51).y
            mouth3x = shape.part(53).x
            mouth3y= shape.part(53).y
            mouth4x = shape.part(55).x
            mouth4y = shape.part(55).y
            mouth5x = shape.part(57).x
            mouth5y = shape.part(57).y
            mouth6x = shape.part(59).x
            mouth6y = shape.part(59).y
            mdata1 = math.sqrt((mouth2x - mouth6x) * (mouth2x - mouth6x) + (mouth2y - mouth6y) * (mouth2y - mouth6y)) + math.sqrt((mouth3x - mouth5x) * (mouth3x - mouth5x) + (mouth3y - mouth5y) * (mouth3y - mouth5y))
            mdata2 = 2 * math.sqrt((mouth1x - mouth4x) * (mouth1x - mouth4x) + (mouth1y - mouth4y) * (mouth1y - mouth4y));
            mouth = mdata1 / mdata2
            # 计算左眼 EAR


            dataLE1 = euclidean_distance(left_eye_coords[1], left_eye_coords[5]) + euclidean_distance(left_eye_coords[2], left_eye_coords[4])
            dataLE2 = 2 * euclidean_distance(left_eye_coords[0], left_eye_coords[3])
            Leye = dataLE1 / dataLE2
            # 计算右眼 EAR

            dataRE1 = euclidean_distance(right_eye_coords[1], right_eye_coords[5]) + euclidean_distance(right_eye_coords[2], right_eye_coords[4])
            dataRE2 = 2 * euclidean_distance(right_eye_coords[0], right_eye_coords[3])
            Reye = dataRE1 / dataRE2
            avg = (Reye + Leye) * 0.5       #计算平均值
            if avg < 0.18:
                ant += 1  # 闭眼次数累加
                minute_ant+=1
            # 在图像上显示统计信息


            if mouth>=0.75:
                cnt+=0.1
                minute_cnt+=0.1

            cv2.putText(frame, f" eye count: {ant}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
            cv2.putText(frame, f"month count: {cnt}", (10, 70), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
            elapsed_time = time.time() - start_time
            if elapsed_time >= 60:
                if(minute_cnt>=3 and minute_ant>=20):
                    cv2.putText(frame,f"You seem fatigued",(10,120),cv2.FONT_HERSHEY_SIMPLEX,0.8,(0,0,255),2)

                print(f"时间 {int(elapsed_time / 60)} - 眨眼次数: {minute_ant}, 嘴巴张开次数: {minute_cnt}")
                start_time = time.time()  # 重置开始时间
                minute_ant = 0  # 重置闭眼次数
                minute_cnt = 0  # 重置嘴巴张开次数

        frames_queue.put(frame)

capture = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

frames_queue = queue.Queue()

# 创建并启动人脸检测线程
face_detection_thread = threading.Thread(target=detect_faces)
face_detection_thread.start()

while True:
    if not frames_queue.empty():
        frame = frames_queue.get()
        cv2.imshow("face", frame)

    if cv2.waitKey(1) & 0xFF == ord(' '):
        break

capture.release()
cv2.destroyAllWindows()

 

标签:eye,项目,备份,cv2,shape,part,coords,time
From: https://www.cnblogs.com/liliczw2209/p/17643258.html

相关文章

  • 社区版idea插件spring assistant开发springboot项目返回jsp
    最近了解到社区版idea没有专门的sringboot,网上网友提供支持说是springboot社区版有几种开发模式:springinitilizer:https://start.spring.io/在线创建springassistant插件支持(具体版本可以去github找)这次我选择第二种,然而在springboot开发返回jsp页面一直报错前端页面报错:后端控......
  • 云服务器下如何部署Flask项目详细操作步骤
    参考网上各种方案,再结合之前学过的Django部署方案,最后确定Flask总体部署是基于:centos7+nginx+uwsgi+python3+Flask之上做的。本地windows开发测试好了我的OCR项目,现在要部署我的OCR项目到云服务器上验证下。第一步:打包上传Flask项目代码到服务器指定目录下如图: 第二步:安装......
  • 项目
    1.分库分表的优化将原来同一个库的表,分别进行区分,有交易库、基础库等等。分库分表,分析原sql中的表,看是否有移动,如果这张表迁移了,sql还是连表状态,就需要重写,重现业务逻辑,写好注解@DS,当@DS注解未起作用时,可以通过在@Transactional注解中添加propagation参数来指定事务的传播......
  • DELPHI 文件自动备份工具源码分享
    一.工具界面如下(没做UI) 二.设计视图如下: 三.控件说明:1.使用到了第三方StyleControl控件中的SCGPLabel,SCGPEdit,SCGPCheckBox,SCGPCombobox,SCGPButton,这几个控件如果需要,可替换成秕自带控件.难度-12.TrayIcon这个是让程序缩小到托盘上面去的.3.Pop......
  • 【路飞项目总结指南】
    【一】路飞项目Gitee链接【1】Gitee之路飞项目前端【2】Gitee之路飞项目后端【二】企业项目相关知识介绍企业级项目介绍【三】路飞项目前期准备【1】前期需求分析【2】虚拟环境介绍与搭建【四】路飞项目搭建准备【1】后端创建项目【2】搭建数据库相关【3】封装全局logg......
  • 硬件管理平台-硬件网关-网关配置项目
    硬件管理平台-硬件网关-网关配置项目简介在本章开始前,我们需要做一下说明,为例更好的服务于网关项目,更好的让前面章节中的xml服务于网关,需要创建一个网关配置页面来新增硬件信息,并进行保存,保存后的xml才能被网关识别,进而让网关进行后续的任务(例如:硬件管理平台-硬件网关-插件模块-......
  • 【5.0】路飞项目之数据库相关
    【一】软件开发模式【1】BBSBBS(BulletinBoardSystem)是一种基于电子信息交流的系统,通常用于在线讨论和发布信息。BBS使用了瀑布开发模式。瀑布开发模式是一种线性的软件开发过程,按照固定的顺序依次完成需求分析、系统设计、编码、测试和运维等阶段。在这个开发模式中,软......
  • 【9.0】路飞项目前端搭建
    【一】Vue2创建项目创建项目vuecreatelufycity_web选择Vue版本(2.0)VueCLIv5.0.8?Pleasepickapreset:(Usearrowkeys)>normal([Vue2]babel,router,vuex)vue3.0_cli([Vue3]babel,router,vuex)Default([Vue3]babel,eslint)D......
  • 【13.0】路飞项目的Gitee
    【一】管理路飞项目忽略一下文件夹及文件.idea*.log__pycache__*.pycscripts【二】忽视部分文件初识化仓库gitinitInitializedemptyGitrepositoryinE:/OldBoy/luffy/luffyCity/.git/查看仓库状态gitstatusOnbranchmasterNocommitsyetUnt......
  • 智慧建筑工地平台源码,数字化项目管理云平台源码
    智慧工地管理平台源码智慧工地管理平台是以物联网、移动互联网技术为基础,充分应用大数据、人工智能、移动通讯、云计算等信息技术,利用前端信息采通过人机交互、感知、决策、执行和反馈等,实现对工程项目內人员、车辆、安全、设备、材料等的智能化管理,是信息技术、人工技术与工程施工......