基于Mediapipe_Unity_Plugin实现手势识别

 GitHub - homuler/MediaPipeUnityPlugin: Unity plugin to run MediaPipehttps://github.com/homuler/MediaPipeUnityPlugin

实现了以下:

public enum HandGesture
{
    None,
    Stop,
    ThumbsUp,
    Victory,
    OK,
    OpenHand
}

核心脚本:

// Copyright (c) 2023 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.using System.Collections;
using Mediapipe.Tasks.Vision.HandLandmarker;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;namespace Mediapipe.Unity.Sample.HandLandmarkDetection
{public class HandLandmarkerRunner : VisionTaskApiRunner<HandLandmarker>{[SerializeField] private HandLandmarkerResultAnnotationController _handLandmarkerResultAnnotationController;private Experimental.TextureFramePool _textureFramePool;public readonly HandLandmarkDetectionConfig config = new HandLandmarkDetectionConfig();public UnityAction<HandLandmarkerResult> ProcessHandLandmark;public override void Stop(){base.Stop();_textureFramePool?.Dispose();_textureFramePool = null;}protected override IEnumerator Run(){Debug.Log($"Delegate = {config.Delegate}");Debug.Log($"Image Read Mode = {config.ImageReadMode}");Debug.Log($"Running Mode = {config.RunningMode}");Debug.Log($"NumHands = {config.NumHands}");Debug.Log($"MinHandDetectionConfidence = {config.MinHandDetectionConfidence}");Debug.Log($"MinHandPresenceConfidence = {config.MinHandPresenceConfidence}");Debug.Log($"MinTrackingConfidence = {config.MinTrackingConfidence}");yield return AssetLoader.PrepareAssetAsync(config.ModelPath);var options = config.GetHandLandmarkerOptions(config.RunningMode == Tasks.Vision.Core.RunningMode.LIVE_STREAM ? OnHandLandmarkDetectionOutput : null);taskApi = HandLandmarker.CreateFromOptions(options, GpuManager.GpuResources);var imageSource = ImageSourceProvider.ImageSource;yield return imageSource.Play();if (!imageSource.isPrepared){Debug.LogError("Failed to start ImageSource, exiting...");yield break;}// Use RGBA32 as the input format.// TODO: When using GpuBuffer, MediaPipe assumes that the input format is BGRA, so maybe the following code needs to be fixed._textureFramePool = new Experimental.TextureFramePool(imageSource.textureWidth, imageSource.textureHeight, TextureFormat.RGBA32, 10);// NOTE: The screen will be resized later, keeping the aspect ratio.screen.Initialize(imageSource);SetupAnnotationController(_handLandmarkerResultAnnotationController, imageSource);var transformationOptions = imageSource.GetTransformationOptions();var flipHorizontally = transformationOptions.flipHorizontally;var flipVertically = transformationOptions.flipVertically;var imageProcessingOptions = new Tasks.Vision.Core.ImageProcessingOptions(rotationDegrees: (int)transformationOptions.rotationAngle);AsyncGPUReadbackRequest req = default;var waitUntilReqDone = new WaitUntil(() => req.done);var waitForEndOfFrame = new WaitForEndOfFrame();var result = HandLandmarkerResult.Alloc(options.numHands);// NOTE: we can share the GL context of the render thread with MediaPipe (for now, only on Android)var canUseGpuImage = SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3 && GpuManager.GpuResources != null;using var glContext = canUseGpuImage ? GpuManager.GetGlContext() : null;while (true){if (isPaused){yield return new WaitWhile(() => isPaused);}if (!_textureFramePool.TryGetTextureFrame(out var textureFrame)){yield return new WaitForEndOfFrame();continue;}// Build the input ImageImage image;switch (config.ImageReadMode){case ImageReadMode.GPU:if (!canUseGpuImage){throw new System.Exception("ImageReadMode.GPU is not supported");}textureFrame.ReadTextureOnGPU(imageSource.GetCurrentTexture(), flipHorizontally, flipVertically);image = textureFrame.BuildGPUImage(glContext);// TODO: Currently we wait here for one frame to make sure the texture is fully copied to the TextureFrame before sending it to MediaPipe.// This usually works but is not guaranteed. Find a proper way to do this. See: https://github.com/homuler/MediaPipeUnityPlugin/pull/1311yield return waitForEndOfFrame;break;case ImageReadMode.CPU:yield return waitForEndOfFrame;textureFrame.ReadTextureOnCPU(imageSource.GetCurrentTexture(), flipHorizontally, flipVertically);image = textureFrame.BuildCPUImage();textureFrame.Release();break;case ImageReadMode.CPUAsync:default:req = textureFrame.ReadTextureAsync(imageSource.GetCurrentTexture(), flipHorizontally, flipVertically);yield return waitUntilReqDone;if (req.hasError){Debug.LogWarning($"Failed to read texture from the image source");continue;}image = textureFrame.BuildCPUImage();textureFrame.Release();break;}switch (taskApi.runningMode){case Tasks.Vision.Core.RunningMode.IMAGE:if (taskApi.TryDetect(image, imageProcessingOptions, ref result)){_handLandmarkerResultAnnotationController.DrawNow(result);}else{_handLandmarkerResultAnnotationController.DrawNow(default);}break;case Tasks.Vision.Core.RunningMode.VIDEO:if (taskApi.TryDetectForVideo(image, GetCurrentTimestampMillisec(), imageProcessingOptions, ref result)){_handLandmarkerResultAnnotationController.DrawNow(result);}else{_handLandmarkerResultAnnotationController.DrawNow(default);}break;case Tasks.Vision.Core.RunningMode.LIVE_STREAM:taskApi.DetectAsync(image, GetCurrentTimestampMillisec(), imageProcessingOptions);break;}}}private void OnHandLandmarkDetectionOutput(HandLandmarkerResult result, Image image, long timestamp){_handLandmarkerResultAnnotationController.DrawLater(result);ProcessHandLandmark?.Invoke(result);}}
}

对于ProcessHandLandmark?.Invoke(result);进行处理手部21个关键点的三维坐标信息。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/94471.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/94471.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 项目构建编译概述

主要内容是Android AOSP源码的管理方式&#xff0c;项目源码的构建和编译&#xff0c;用到比如git、repo、gerrit一些命令工具&#xff0c;以及使用Soong编译系统&#xff0c;编写Android.bp文件的格式样式。 1. Android操作系统堆栈概述 Android 是一个针对多种不同设备类型打…

Python爬虫08_Requests聚焦批量爬取图片

一、Requests聚焦批量爬取图片 import re import requests import os import timeurl https://www.douban.com/ userAgent {User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0}#获取整个浏览页面 page_text requests.get(urlur…

Spring Cloud系列—简介

目录 1 单体架构 2 集群与分布式 3 微服务架构 4 Spring Cloud 5 Spring Cloud环境和工程搭建 5.1 服务拆分 5.2 示例 5.2.1 数据库配置 5.2.2 父子项目创建 5.2.3 order_service子项目结构配置 5.2.4 product_service子项目结构配置 5.2.5 服务之间的远程调用 5.…

【普中STM32精灵开发攻略】--第 1 章 如何使用本攻略

学习本开发攻略主要参考的文档有《STM32F1xx 中文参考手册》和《Cortex M3权威指南(中文)》&#xff0c;这两本都是 ST 官方手册&#xff0c;尤其是《STM32F1xx 中文参考手册》&#xff0c;里面包含了 STM32F1 内部所有外设介绍&#xff0c;非常详细。大家在学习 STM32F103的时…

【Docker】RK3576-Debian上使用Docker安装Ubuntu22.04+ROS2

1、简述 RK3576自带Debian12系统,如果要使用ROS2,可以在Debian上直接安装ROS2,缺点是有的ROS包需要源码编译;当然最好是使用Ubuntu系统,可以使用Docker安装,或者构建Ubuntu系统,替换Debian系统。 推荐使用Docker来安装Ubuntu22.04,这里会有个疑问,是否可以直接使用Do…

解决docker load加载tar镜像报json no such file or directory的错误

在使用docker加载离线镜像文件时&#xff0c;出现了json no such file or directory的错误&#xff0c;刚开始以为是压缩包拷贝坏了&#xff0c;重新拷贝了以后还是出现了问题。经过网上查找方案&#xff0c;并且自己实践&#xff0c;采用下面的简单方法就可以搞定。 归结为一句…

《协作画布的深层架构:React与TypeScript构建多人实时绘图应用的核心逻辑》

多人在线协作绘图应用的构建不仅是技术栈的简单组合,更是对实时性、一致性与用户体验的多维挑战。基于React与TypeScript开发这类应用,需要在图形绘制的基础功能之外,解决多用户并发操作的同步难题、状态回溯的逻辑冲突以及大规模协作的性能瓶颈。每一层架构的设计,都需兼顾…

智慧社区(八)——社区人脸识别出入管理系统设计与实现

在社区安全管理日益智能化的背景下&#xff0c;传统的人工登记方式已难以满足高效、精准的管理需求。本文将详细介绍一套基于人脸识别技术的社区出入管理系统&#xff0c;该系统通过整合腾讯云 AI 接口、数据库设计与业务逻辑&#xff0c;实现了居民出入自动识别、记录追踪与访…

嵌入式开发学习———Linux环境下IO进程线程学习(四)

进程相关函数fork创建一个子进程&#xff0c;子进程复制父进程的地址空间。父进程返回子进程PID&#xff0c;子进程返回0。pid_t pid fork(); if (pid 0) { /* 子进程代码 */ } else { /* 父进程代码 */ }getpid获取当前进程的PID。pid_t pid getpid();getppid获取父进程的P…

标记-清除算法中的可达性判定与Chrome DevTools内存分析实践

引言 在现代前端开发中&#xff0c;内存管理是保证应用性能与用户体验的核心技术之一。作为JavaScript运行时的基础机制&#xff0c;标记-清除算法(Mark-and-Sweep) 通过可达性判定决定哪些内存需要回收&#xff0c;而Chrome DevTools提供的Memory工具则为开发者提供了深度的内…

微算法科技(NASDAQ:MLGO)基于量子重加密技术构建区块链数据共享解决方案

随着信息技术的飞速发展&#xff0c;数据已成为数字经济时代的核心生产要素。数据的共享和安全往往是一对难以调和的矛盾。传统的加密方法在面对日益强大的计算能力和复杂的网络攻击时&#xff0c;安全性受到了挑战。微算法科技(NASDAQ&#xff1a;MLGO)通过引入量子重加密技术…

FastAPI快速入门P2:与SpringBoot比较

欢迎来到啾啾的博客&#x1f431;。 记录学习点滴。分享工作思考和实用技巧&#xff0c;偶尔也分享一些杂谈&#x1f4ac;。 有很多很多不足的地方&#xff0c;欢迎评论交流&#xff0c;感谢您的阅读和评论&#x1f604;。 目录引言1 FastAPI事件管理2 类的使用2.1 初始化方法对…

SAP-ABAP: Open SQL集合函数COUNT(统计行数)、SUM(数值求和)、AVG(平均值)、MAX/MIN(极值)深度指南

SAP Open SQL集合函数深度指南 1. 核心价值与特性函数作用关键特性COUNT统计行数用COUNT(*)包含NULL值行&#xff0c;COUNT(字段)排除NULLSUM数值求和自动过滤NULL值&#xff0c;结果类型与源字段相同AVG平均值必须用TYPE f接收&#xff0c;否则四舍五入导致精度丢失MAX/MIN极值…

【docker】UnionFS联合操作系统

Linux 的 Namespace、CGroups 和 UnionFS 三大技术支撑了 Docker 的实现。 一、为什么需要联合文件系统&#xff1f;在传统操作系统中&#xff0c;每个文件系统都是独立的孤岛。但当我们需要&#xff1a;合并多个目录的内容保持基础系统不变的同时进行修改高效共享重复文件内容…

CTF-XXE 漏洞解题思路总结

一、XXE 漏洞简介XXE (XML External Entity) 漏洞允许攻击者通过构造恶意的 XML 输入&#xff0c;强迫服务器的 XML 解析器执行非预期的操作。在 CTF 场景中&#xff0c;最常见的利用方式是让解析器读取服务器上的敏感文件&#xff0c;并将其内容返回给攻击者。二、核心攻击载荷…

GitLab:一站式 DevOps 平台的全方位解析

GitLab&#xff1a;一站式 DevOps 平台的全方位解析 在当今数字化时代&#xff0c;软件研发的效率与质量直接决定企业的市场竞争力。GitLab 作为全球领先的 DevOps 平台&#xff0c;凭借 “从构思到部署” 的全流程管理能力&#xff0c;已成为无数企业加速软件交付的核心工具。…

Flink富函数:一种更灵活、可扩展的方式来定义数据流的处理逻辑

本文重点 Flink中的富函数类是一组用于处理数据流的函数接口和实现类。富函数类提供了一种更灵活和可扩展的方式来定义数据流的处理逻辑。 富函数类 富函数类是DataStream API提供的一个函数类的接口,所有的Flink函数类都有其Rich版本。富函数类一般是以抽象类的形式出现的。…

【STM32】HAL库中的实现(四):RTC (实时时钟)

&#x1f552;HAL库中的实现&#xff1a;RTC&#xff08;Real-Time Clock&#xff09;实时时钟RTC 是 STM32 的低功耗实时时钟模块&#xff0c;常用于&#xff1a; 实时时间维护&#xff08;年月日时分秒&#xff09;定时唤醒日志时间戳闹钟功能RTC&#xff08;实时时钟&#x…

Pauli 矩阵指数函数展开为显式矩阵 e^A -> B

要展开表达式 为普通矩阵&#xff0c;其中 是 Pauli 矩阵&#xff0c; 是单位向量&#xff0c; 是实数。以下是详细推导步骤&#xff1a;1. Pauli 矩阵的性质Pauli 矩阵定义为&#xff1a;它们满足以下关系&#xff1a;​其中 是 Kronecker delta&#xff0c;​ 是 Levi-…

【Algorithm | 0x03 搜索与图论】DFS

DFS基础知识典型例题例1&#xff1a;n皇后问题例2&#xff1a;拍照例3&#xff1a;理发基础知识 核心原理&#xff1a;一条路走到黑 示意图&#xff1a;其含义表示&#xff0c;在这个图中顶层是第0层&#xff0c;也就是后面dfs的入口&#xff0c;一般从dfs(0)开始操作。 模版&a…