更稳定的手势识别方法-基于手部骨架与关键点检测
导读
本期将介绍并演示基于MediaPipe的手势骨架与特征点提取步骤以及逐步为基础实现手势识别的方法。
介绍
关于MediaPipe以前有相关文章介绍,可以参见以下链接:
Google开源手势识别-基于TF Lite / MediaPipe
它能做些什么?它支持的语言和平台有什么?请看下面两张图:
我们主要介绍手势骨骼与关键点提取,其他内容大家有兴趣自主学习了解。github地址:https://github.com/google/mediapipe
效果展示
手势骨骼提取与关键点标注:
手势骨架与关键点提取-计算机视觉
手势识别0〜6:
手势识别-提前祝大家新年快乐
实现步骤
具体可参考下面链接:
https://google.github.io/mediapipe/solutions/hands
(1)安装mediapipe,执行pip install mediapipe
(2)下载手势检测与骨架提取模型,地址:
https://github.com/google/mediapipe/tree/master/mediapipe/modules/hand_landmark
(3)代码测试(摄像头实时测试):
import cv2
import mediapipe as mp
from os import listdir
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(
min_detection_confidence=0.5, min_tracking_confidence=0.5)
cap = cv2.VideoCapture(0)
while cap.isOpened():
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
continue
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)
image.flags.writeable = False
results = hands.process(image)
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imshow('result', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cv2.destroyAllWindows()
hands.close()
cap.release()
输出与结果:
图片检测(可支持多个手掌):
import cv2
import mediapipe as mp
from os import listdir
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
# For static images:
hands = mp_hands.Hands(
static_image_mode=True,
max_num_hands=5,
min_detection_confidence=0.2)
img_path = './multi_hands/'
save_path = './'
index = 0
file_list = listdir(img_path)
for filename in file_list:
index += 1
file_path = img_path + filename
# Read an image, flip it around y-axis for correct handedness output (see
# above).
image = cv2.flip(cv2.imread(file_path), 1)
# Convert the BGR image to RGB before processing.
results = hands.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
# Print handedness and draw hand landmarks on the image.
print('Handedness:', results.multi_handedness)
if not results.multi_hand_landmarks:
continue
image_hight, image_width, _ = image.shape
annotated_image = image.copy()
for hand_landmarks in results.multi_hand_landmarks:
print('hand_landmarks:', hand_landmarks)
print(
f'Index finger tip coordinates: (',
f'{hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].x * image_width}, '
f'{hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y * image_hight})'
)
mp_drawing.draw_landmarks(
annotated_image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imwrite(
save_path + str(index) + '.png', cv2.flip(annotated_image, 1))
hands.close()
# For webcam input:
hands = mp_hands.Hands(
min_detection_confidence=0.5, min_tracking_confidence=0.5)
cap = cv2.VideoCapture(0)
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 = hands.process(image)
# Draw the hand annotations on the image.
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imshow('result', image)
if cv2.waitKey(5) & 0xFF == 27:
break
cv2.destroyAllWindows()
hands.close()
cap.release()
总结后续说明
总结:MediaPipe手势检测与骨架提取模型识别相较传统方法更稳定,而且提供手指关节的三维坐标点,对于手势识别与进一步手势动作相关开发有很大帮助。
其他说明:
(1)手部关节点标记与排序定义如下图:
(2)手部关节点坐标(x,y,z)输出为小于1的小数,需要归一化后显示到图像上,这部分可以查看上部分源码后转到定义查看,这里称为演示代码,另外的Z坐标靠近屏幕扩大,超出屏幕尺寸:
def Normalize_landmarks(image, hand_landmarks):
new_landmarks = []
for i in range(0,len(hand_landmarks.landmark)):
float_x = hand_landmarks.landmark[i].x
float_y = hand_landmarks.landmark[i].y
# Z坐标靠近屏幕增大,远离屏幕减小
float_z = hand_landmarks.landmark[i].z
print(float_z)
width = image.shape[1]
height = image.shape[0]
pt = mp_drawing._normalized_to_pixel_coordinates(float_x,float_y,width,height)
new_landmarks.append(pt)
return new_landmarks
(3)根据此您可以做一个简单的额度识别识别或手势靠近远离屏幕的小程序,当然还要要考虑关节点的坐标,可能还需要计算角度已经以前的状态等等,某种以下这样:
其他演示与相关代码均在知识星球主题中发布,需要的朋友可以加入获取。另外后续有时间更新C ++版本也将直接发布在知识星球中。
觉得有用,麻烦给个赞和在看
更稳定的手势识别方法-基于手部骨架与关键点检测相关推荐
- 更稳定的手势识别方法--基于手部骨架与关键点检测
导读 本期将介绍并演示基于MediaPipe的手势骨架与特征点提取步骤以及以此为基础实现手势识别的方法. 介绍 关于MediaPipe以前有相关文章介绍,可以参看下面链接: Google开源手势识别- ...
- 手部21个关键点检测+手势识别-[MediaPipe]
MediaPipe 是一款由 Google Research 开发并开源的多媒体机器学习模型应用框架,可以直接调用其API完成目标检测.人脸检测以及关键点检测等.本篇文章介绍其手部21个关键点检测(w ...
- PyTorch深度学习实战 | 基于ResNet的人脸关键点检测
人脸关键点检测指的是用于标定人脸五官和轮廓位置的一系列特征点的检测,是对于人脸形状的稀疏表示.关键点的精确定位可以为后续应用提供十分丰富的信息.因此,人脸关键点检测是人脸分析领域的基础技术之一.许多应 ...
- 基于 OpenCV 的面部关键点检测实战
[ 编者按]这篇文章概述了用于构建面部关键点检测模型的技术,这些技术是Udacity的AI Nanodegree程序的一部分. 作者 | 小白 责编 | 欧阳姝黎 概述 在Udacity的AIND的最 ...
- 谷歌发布 MediaPipe Holistic,实现移动端同时进行人脸、手部和人体关键点检测跟踪...
作者:Ivan Grishchenko & Valentin Bazarevsky 编译:CV君 谷歌MediaPipe Holistic为突破性的 540 多个关键点(33 个姿势.21 个 ...
- 【Opencv】基于dlib的人脸关键点检测和闭眼检测
关键点定位 #导入工具包 from collections import OrderedDict import numpy as np import argparse import dlib impo ...
- OpenCV基于dlib进行人脸关键点检测(摄像头)
1. dlib.get_frontal_face_detector()获取人脸检测器 2. dlib.shape_predictor()预测人脸关键点 人脸关键点模型,下载地址: http://dli ...
- 基于深度学习的目标检测方法综述
引言 现有的深度学习的目标检测方法,可以大致分为两类:一.基于候选区域的目标检测方法:二.基于回归的目标检测方法.依据方法的提出时间,可以构建出如下时间线: 2014 CVPR R-CNN[1] 20 ...
- 一种基于深度学习的目标检测提取视频图像关键帧的方法
摘要:针对传统的关键帧提取方法误差率高.实时性差等问题,提出了一种基于深度学习的目标检测提取视频图像关键帧的方法,分类提取列车头部.尾部及车身所在关键帧.在关键帧提取过程中,重点研究了基于SIFT特征 ...
最新文章
- Python之递归函数
- 【已解决】Jsp实现文件上传功能
- 如何用Fiddler对手机(安卓/iOS)数据进行抓包
- jQuery 基础教程 (三)之jQuery的选择器
- 中南大学12月13日考c语言,中南大学2010级C语言试卷
- LeetCode(40):组合总和 II
- Python编程基础12:函数和模块
- oracle 01035,oracle常用命令(一)
- 加州出台严格无人车路测新政:要求各公司尽快申请部署许可
- grafana高可用架构
- [转载]INNO Setup 使用笔记
- swift——富文本文字的简单使用
- WS2:Windows系统中嵌入式Linux开发之神器
- CSDN写博客怎么插入数学公式(干货满满呦)
- 易辅客栈 从零学辅助_如何从零启动辅助项目
- abb机器人goto指令用法_ABB机器人程序指令解读,建议收藏
- python-expected an indented block问题解决
- pandas+groupby对南京二手房进行数据可视化及大图显示
- 如何用 SSH 登录 Kindle 系统
- 基于php抑郁症自检测及初级自治疗网站
热门文章
- 给程序员的营销课:提升下单率,首先从图标开始!
- 报纸页数(X星球日报和我们地球的城市早报是一样的, 都是一些单独的纸张叠在一起而已。每张纸印有4版。 比如,某张报纸包含的4页是:5,6,11,12, 可以确定它应该是最上边的第2张报纸。 我们)
- echarts父组件向子组件传值报错
- minecraft_我们未来的机器人影响者:尝试使用Minecraft玩的Twitch流媒体机器人
- C语言简易程序设计————20、寻找完数
- 茄子快传,中国企业海外进军的绿色通道
- 正则表达式[^\\.]
- scikit-learn_LinearModel_02_峰回归和峰归类
- 大数据技术与应用实验报告3
- 史上最牛的论坛推广方法,论坛推广实战方案!