人脸468个特征点检测——Google MediaPipe Face Mesh

win10,python,opencv,MediaPipe

代码参考地址:https://google.github.io/mediapipe/solutions/face_mesh

MediaPipe :https://google.github.io/mediapipe/

参考文献:Real-time Facial Surface Geometry from Monocular Video on Mobile GPUs

地址:https://arxiv.org/abs/1907.06724

代码功能简介:

1. 打开摄像头

2. 显示每一帧图像;每帧检测两张人脸;图像附加显示帧率(左上角)、人脸468个特征点;在输出窗口打印468个点的坐标(id,x,y,z)

3. 按Esc退出

-------------------------

第一步:安装opencv,MediaPipe模块:

pip install opencv-python
pip install mediapipe

第二步:

创建facemesh.py文件,代码如下:

import cv2
import mediapipe as mp
import time


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


# For webcam input:
drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
cap = cv2.VideoCapture(0)
pTime = 0

with mp_face_mesh.FaceMesh(
    max_num_faces=2,
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5) as face_mesh:
  while cap.isOpened():
    success, image = cap.read()
    if not success:
      print("Ignoring empty camera frame.")
      # If loading a video, use 'break' instead of 'continue'.
      continue

    # Flip the image horizontally for a later selfie-view display, and convert
    # the BGR image to RGB.
    image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
    # To improve performance, optionally mark the image as not writeable to
    # pass by reference.
    image.flags.writeable = False
    results = face_mesh.process(image)

    # Draw the face mesh annotations on the image.
    # and print landmarks' id, x, y, z 
    image.flags.writeable = True
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    if results.multi_face_landmarks:
      for face_landmarks in results.multi_face_landmarks:
        # Draw landmarks on the image.
        mp_drawing.draw_landmarks(
            image=image,
            landmark_list=face_landmarks,
            connections=mp_face_mesh.FACE_CONNECTIONS,
            landmark_drawing_spec=drawing_spec,
            connection_drawing_spec=drawing_spec)
        # print id, x, y, z
        # time cost 
        """
        for id,lm in enumerate(face_landmarks.landmark):
            ih, iw, ic = image.shape
            x,y = int(lm.x*iw), int(lm.y*ih)
            print(id, x,y,lm.z)
        """
        
    cTime = time.time()
    fps = 1/(cTime-pTime)
    pTime = cTime
    cv2.putText(image, f'FPS:{int(fps)}', (10,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)

    cv2.imshow('MediaPipe FaceMesh', image)
    if cv2.waitKey(1) & 0xFF == 27:
      cv2.destroyAllWindows()
      cap.release()
      break

第三步:运行。结果如下:

 

输出窗口:(id, x, y, z)

(0-467共468个点,x,y已转换成像素坐标)

  第四步:按Esc键退出。

### 面部深度伪造检测的方法、工具及研究 #### 方法概述 对于面部深度伪造(Deepfake)的检测,现有方法主要集中在发现图像或视频序列中存在的不一致性上。这些不一致可能源于生成对抗网络(GANs)或其他合成技术所固有的局限性。当面对高质量的Deepfake样本时,传统的基于人工特征提取的方式变得不再有效;因此,研究人员转向了更加先进的机器学习手段。 一种有效的策略是采用多模态融合方案,即综合考虑音频流、唇语同步度以及眼部运动等多个维度的信息来进行判断[^4]。此外,还有学者提出利用时间连贯性和物理规律作为判别依据之一——例如眨眼频率异常或是光照条件下的阴影变化不符合实际逻辑等现象均能成为识别线索的一部分。 #### 工具介绍 针对日益增长的安全需求和技术挑战,多个开源项目应运而生: - **FaceForensics++**: 提供了一个大规模标注好的数据集用于训练和评估不同的deepfake检测算法; - **DeepFake Detection Challenge (DFDC)**: 由Facebook发起的比赛平台不仅促进了社区内的交流协作,同时也催生了一系列创新性的解决方案; - **MediaPipe Face Mesh API**: 谷歌开发的一款实时追踪人脸几何结构的应用程序接口(API),可用于辅助构建高效的预处理模块,在初步筛选阶段排除明显错误案例。 #### 研究进展 近期一项重要研究成果来自一篇题为《基于框架推理的Deepfake检测》的文章中提到的新颖架构—FInfer Framework。该模型通过引入自回归机制来捕捉时空域上的动态特性,并以此为基础实现了对未来画面内容的有效预测。实验结果显示这种方法能够在保持较高准确性的同时具备良好的泛化能力,尤其适用于那些经过精心制作难以察觉破绽的目标对象。 ```python import torch.nn as nn class FInfer(nn.Module): def __init__(self, input_size=128, hidden_dim=512, num_layers=2): super().__init__() self.lstm = nn.LSTM(input_size=input_size, hidden_size=hidden_dim, num_layers=num_layers, batch_first=True) def forward(self, x): out, _ = self.lstm(x) return out[:, -1, :] ```
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值