惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
Scott Helme
Scott Helme
Google Online Security Blog
Google Online Security Blog
L
LINUX DO - 最新话题
O
OpenAI News
S
Secure Thoughts
Cisco Talos Blog
Cisco Talos Blog
Forbes - Security
Forbes - Security
V
Visual Studio Blog
有赞技术团队
有赞技术团队
Jina AI
Jina AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Troy Hunt's Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Schneier on Security
雷峰网
雷峰网
The Cloudflare Blog
量子位
Last Week in AI
Last Week in AI
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
B
Blog RSS Feed
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
G
GRAHAM CLULEY
MyScale Blog
MyScale Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Schneier on Security
Schneier on Security
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
S
Security Affairs
A
Arctic Wolf
T
Tenable Blog
PCI Perspectives
PCI Perspectives
Spread Privacy
Spread Privacy
AI
AI
L
LangChain Blog
Latest news
Latest news
博客园 - 叶小钗
博客园 - Franky
T
Threatpost
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
在 Snap! 中使用 mediapipe 库
种瓜 · 2024-05-09 · via 夜行人

文章目录

English version

MediaPipe 提供了一套库和工具,供用户在应用程序中快速应用人工智能 (AI) 和机器学习 (ML) 技术 – Github/MediaPipe

这些灵活的工具构建在 TensorFlow Lite 之上 – mediapipe homepage

Mediapipe 提供了一系列预训练的模型和处理工具,用于处理各种媒体数据。这些模型可以用于各种用途,如姿态检测、手部追踪、人脸检测、手势识别等 – ChatGPT

视频讲解

目标

我们希望引入 mediapipe 的所有工作都完全在积木环境中完成!

这样有如下好处:

  1. 无需更新平台, 不需要开发者介入, 所有工作都在用户环境中完成(只是一个 Snap! 项目), 这意味着普通用户可以继续扩展这些能力。 (这是终端用户编程的一个例子)
  2. 可以充分利用 Snap! 的活性(liveness), 享受高效而愉快的开发体验。

动态导入

mediapipe 提供了 JavaScript API, 因此我们似乎可以通过 JavaScript function 将 mediapipe 引入到 Snap! 中。

import() 可以将 ECMAScript 模块异步动态加载到非模块环境中, 它正是我们需要的。

让我们试着引入 mediapipe 库。mediapipe有丰富的功能, 我们打算制作的一个例子是 Gesture Recognition(点击体验)。参考了 mediapipe 的文档使用案例

项目代码:

以下介绍关键的部分.

首先是使用 import() 动态引入模块:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// 避免重复导入
if (window.FilesetResolver) {return}

// https://developers.google.com/mediapipe/api/solutions/js/tasks-vision
url = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.13" // @latest
import(url).then(vision => {
  // 将模块中的函数, 放到全局变量里
  window.FilesetResolver = vision.FilesetResolver;
  window.GestureRecognizer = vision.GestureRecognizer;
  window.DrawingUtils = vision.DrawingUtils;
});

导入后就可以使用模块中的函数:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// https://codepen.io/mediapipe-preview/details/zYamdVd
// url 中的资源可托管到国内
if (window.gestureRecognizer) {return}
const createGestureRecognizer = async () => {
  const vision = await FilesetResolver.forVisionTasks(
    "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.13/wasm"
  );
  gestureRecognizer = await GestureRecognizer.createFromOptions(vision, {
    baseOptions: {
      // "https://scratch3-files.just4fun.site/gesture_recognizer.task"
      modelAssetPath: "https://storage.googleapis.com/mediapipe-models/gesture_recognizer/gesture_recognizer/float16/1/gesture_recognizer.task", 
      delegate: "GPU"
    },
    numHands: 2,
  });
  window.gestureRecognizer = gestureRecognizer;
  // demosSection.classList.remove("invisible");
};
createGestureRecognizer();

之后就可以使用 gestureRecognizer 识别图片.

绘制手部关键点

官方示例中不仅给出了手势结果, 还将绘制出了关键点:

手部关键点的含义如下:

从官方示例的代码中可以看出, 绘制工作使用了 drawingUtils, 相比于去阅读 drawingUtils 代码(通常非常乏味), 我更愿意基于原始数据在 Snap! 中绘图, 这样我们可以充分享受 Snap! 活性(liveness)的好处。Snap! 的画笔功能非常易用和强大, 我们可以通过它来画图:

具体而言, 将 results.landmarks 包含的坐标信息使用画笔绘制出来。在这个过程中需要将 mediapipe 的坐标系转化(左上角为原点, y 轴正方向向下)为 Snap! 坐标系。

在绘制的过程中, Snap! 作为交互式个人计算愿景的产物, 其包含的特性(liveness 等)特别有助于探索数据, 用户可以交互式地观察数据:

对当前的某一桢感兴趣时, 可以暂停程序, 将系统定格在这个瞬间:

仿佛冻结了时间, 探索完当前时间截面的数据, 继续恢复程序。

具体参考 项目代码

在示例项目中, 我们只绘制了 1 只手的数据, results.landmarks 有可能会包含 2 只手的数据。

与 MicroBlocks 的互操作

mediapipe 可以充分利用边缘设备(手机/平板)的计算能力, 来提供 AI 功能。 边缘设备的算力越来越强, 苹果最近推出的 M4 芯片 拥有苹果有史以来最快的神经引擎,每秒能够执行高达 38 万亿次操作。 苹果的人工智能战略似乎是在边缘设备上进行推理/学习。

随着 WebGPU 的标准化, Snap! 将可以充分利用到这些性能, 由于 Snap! 也可以基于蓝牙无线连接 MicroBlocks 设备, 以此我们似乎可以将手机用作单片机的算力, 使用 mediapipe 这样的框架, 使用手机制作一个无线 AI 摄像头(就像二哈识图(HuskyLens)摄像头)似乎是很容易的。

FAQ

如何加速国内的访问速度

官方的 mediapipe 库托管国外的 CDN (jsdelivr), 而模型放在 Google 云存储上, 这都使得国内无法访问。 你可以将它们全都托管在国内的云服务上。参考前边的这个例子: mediapipe demo(托管在国内)

参考