眼镜眨巴眨巴-一步几个脚印从头设计数字生命2——仙盟创梦IDE

 

import cv2
import mediapipe as mp
import numpy as np
import time

mp_drawing = mp.solutions.drawing_utils
mp_face_mesh = mp.solutions.face_mesh

# 加载图片
image = cv2.imread('wlzc.jpg')  #
image_height, image_width, _ = image.shape

# 初始化面部网格模型
with mp_face_mesh.FaceMesh(
        static_image_mode=False,
        max_num_faces=1,
        min_detection_confidence=0.5,
        min_tracking_confidence=0.5) as face_mesh:

    # 将图像转换为RGB格式
    image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # 处理图像
    results = face_mesh.process(image_rgb)

    if results.multi_face_landmarks:
        for face_landmarks in results.multi_face_landmarks:
            # 定义眼睛区域的关键点索引
            left_eye_indices = [362, 382, 381, 380, 374, 373, 390, 249, 263, 466, 388, 387, 386, 385, 384, 398]
            right_eye_indices = [33, 7, 163, 144, 145, 153, 154, 155, 133, 173, 157, 158, 159, 160, 161, 246]

            # 提取眼睛关键点坐标
            left_eye_landmarks = np.array([[int(landmark.x * image_width), int(landmark.y * image_height)]
                                           for idx, landmark in enumerate(face_landmarks.landmark) if idx in left_eye_indices])
            right_eye_landmarks = np.array([[int(landmark.x * image_width), int(landmark.y * image_height)]
                                            for idx, landmark in enumerate(face_landmarks.landmark) if idx in right_eye_indices])

            # 模拟眨眼逻辑(简单示例,可根据需要优化)
            blink_interval = 3  # 眨眼间隔时间(秒)
            blink_duration = 0.5  # 眨眼持续时间(秒)
            last_blink_time = time.time()
            is_blinking = False
            blink_start_time = 0

            while True:
                current_time = time.time()
                # 绘制眼睛关键点
                for eye_landmarks in [left_eye_landmarks, right_eye_landmarks]:
                    cv2.polylines(image, [eye_landmarks], isClosed=True, color=(0, 255, 0), thickness=2)

                # 模拟眨眼
                if current_time - last_blink_time > blink_interval and not is_blinking:
                    is_blinking = True
                    blink_start_time = current_time
                elif is_blinking and current_time - blink_start_time > blink_duration:
                    is_blinking = False
                    last_blink_time = current_time
                if is_blinking:
                    # 这里简单地清空眼睛区域来模拟眨眼效果
                    for eye_landmarks in [left_eye_landmarks, right_eye_landmarks]:
                        cv2.fillPoly(image, [eye_landmarks], (0, 0, 0))

                cv2.imshow('Blinking Eyes', image)
                if cv2.waitKey(1) & 0xFF == 27:  # 按下Esc键退出
                    break

cv2.destroyAllWindows()

---

import cv2
import mediapipe as mp
import numpy as np
import time

mp_drawing = mp.solutions.drawing_utils
mp_face_mesh = mp.solutions.face_mesh

# 加载图片
image = cv2.imread('wlzc.jpg')  # 请将 'your_image.jpg' 替换为实际的图片路径
image_height, image_width, _ = image.shape

mediapipe

MediaPipe 是一个由 Google 开发的开源跨平台框架,可用于构建多模式应用程序中的机器学习管道。它提供了一系列的工具和预训练模型,能够帮助开发者快速实现诸如人脸检测、手部追踪、姿势估计等计算机视觉任务。以下从多个方面为你详细介绍

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值