【一步步开发AI运动小程序】六、人体骨骼图绘制
随着人工智能技术的不断发展,阿里体育等IT大厂,推出的“乐动力”、“天天跳绳”AI运动APP,让云上运动会、线上运动会、健身打卡、AI体育指导等概念空前火热。那么,能否将这些在APP成功应用的场景搬上小程序,分享这些概念的红利呢?本系列文章就带您一步一步从零开始开发一个AI运动小程序,本系列文章将使用“云智AI运动识别小程序插件”,请先行在微信服务市场或官网了解详情。
一、骨骼图绘制原理
人体骨骼图的绘制,是通过在camera组件上附一个同等大小的透明canvas组件,在上面绘制关键点达到与人体图像重合的目的。
二、绘制代码
<template>
<view class="human-detection">
<camera id="preview" class="preview" :style="videoStyles" flash="off" :device-position="deviceKey"
resolution="high" frame-size="low" @initdone="onCameraReady">
</camera>
<canvas v-if="poseDrawEnabled" class="preview graphs" type="2d" id="graphics" :style="videoStyles"></canvas>
</view>
</template>
<script>
const AiSports = requirePlugin("aiSport");
const PoseGraphs = AiSports.PoseGraphs;
const humanDetection = AiSports.humanDetection;
export default {
data() {
return {
zoom: 1,
deviceKey: "back",
previewWidth: 480,
previewHeight: 640,
previewRate: 1,
frameWidth: 480,
frameHeight: 640,
status: 'unknown',
fps: 0,
poseFps: 0,
isHumanBody: false
};
},
computed: {
videoStyles() {
const style = `width:${this.previewWidth}px;height:${this.previewHeight}px;`;
return style;
}
},
mounted() {
this.autoFitPreview(480, 640);
this.initCanvas();
},
methods: {
autoFitPreview(width, height) {
const sifno = uni.getSystemInfoSync();
let rate = sifno.windowWidth / width;
this.previewWidth = width * rate;
this.previewHeight = height * rate;
this.previewRate = rate;
this.frameWidth = width;
this.frameHeight = height;
},
initCanvas() {
const that = this;
const query = uni.createSelectorQuery().in(that);
query.select('#graphics')
.fields({
node: true,
size: true
})
.exec((res) => {
if (utils.isEmptyArray(res))
return;
const canvas = res[0].node;
const ctx = canvas.getContext('2d');
const dpr = uni.getSystemInfoSync().pixelRatio;
canvas.width = res[0].width * dpr;
canvas.height = res[0].height * dpr;
ctx.scale(dpr, dpr);
that.canvas = canvas;
that.ctx = ctx;
that.poseGraphs = new PoseGraphs(ctx, canvas.width, canvas.height, 1);
that.poseGraphs.lineColor = "#FF8E148C";//线条颜色
});
},
async detection(frame) {
const human = await humanDetection.detectionAsync(frame);
//无结果
if (!human)
this.poseGraphs.clear();
else
this.poseGraphs.drawing(human.keypoints);
},
initVideo() {
if (this.camera)
return;
const that = this;
this.camera = new CameraDevice();
this.camera.onFrame = frame => {
that.fps = that.camera.fps;
//重新自适应
if (frame.width != that.frameWidth || frame.height != that.frameHeight) {
that.autoFitPreview(frame.width, frame.height);
that.initCanvas();
}
that.detection(frame);
};
}
}
}
</script>
<style lang="scss">
.human-detection {
width: auto;
height: auto;
.preview {
margin: auto;
width: 480px;
height: 640px;
}
.graphs {
position: absolute;
top: 0;
left: 0;
z-index: 9999;
box-shadow: 0 0 14.4928rpx #CCC;
background-color: rgba(0, 0, 0, 0.01);
}
}
</style>
三、注意事项
小程序的抽帧图像大小与camera实时图像可能不一致(https://developers.weixin.qq.com/miniprogram/dev/component/camera.html#Bug-Tip),所以camera和canvas组件必须保持与帧图像保持同比缩放,否则可能导致骨骼与实时图像不一致。
下篇我们将为您介绍如何进行运动分析,敬请期待...
【一步步开发AI运动小程序】六、人体骨骼图绘制的更多相关文章
- Java可视化日历(Date类、DATe Format类、Calendar类综合运用),开发可视化日历小程序
Java时间日期类综合运用,开发可视化日历小程序 由键盘输入指定格式的日期,打印这个月的日历 1.代码 import java.text.DateFormat; import java.text.Pa ...
- 开发一个微信小程序教程
一.注册小程序账号 1.进入微信公众平台(https://mp.weixin.qq.com/),注册小程序账号,根据提示填写对应的信息即可. 2.注册成功后进入首页,在 小程序发布流程->小程序 ...
- 开发一个微信小程序项目教程
一.注册小程序账号 1.进入微信公众平台(https://mp.weixin.qq.com/),注册小程序账号,根据提示填写对应的信息即可.2.注册成功后进入首页,在 小程序发布流程->小程序开 ...
- 如何快速地开发一个微信小程序
如何快速地开发一个微信小程序呢?我觉得作为初学者,最好能有一个模板,然后改这个模板. 同样作为初学者,刚开始的时候我有下面的几个问题,后来通过问同学,我弄清楚了. 微信小程序可以连接MySQL或者Sq ...
- 全栈开发工程师微信小程序-中(下)
全栈开发工程师微信小程序-中(下) 微信小程序视图层 wxml用于描述页面的结构,wxss用于描述页面的样式,组件用于视图的基本组成单元. // 绑定数据 index.wxml <view> ...
- 全栈开发工程师微信小程序-中(中)
全栈开发工程师微信小程序-中(中) 开放能力 open-data 用于展示微信开放的数据 type 开放数据类型 open-gid 当 type="groupName" 时生效, ...
- 全栈开发工程师微信小程序-中
全栈开发工程师微信小程序-中 多媒体及其他的组件 navigator 页面链接 target 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram url 当前小程序内的跳转链 ...
- 全栈开发工程师微信小程序-上(下)
全栈开发工程师微信小程序-上(下) icon 图标 success, success_no_circle, info, warn, waiting, cancel, download, search, ...
- 全栈开发工程师微信小程序-上(中)
全栈开发工程师微信小程序-上(中) width: 750rpx; 750rpx代表与屏幕等宽,rpx的缩写responsive pixel,这个单位是可以根据屏幕大小进行自适应调整的像素单位. 小程序 ...
- 全栈开发工程师微信小程序 - 上
全栈开发工程师微信小程序-上 实现swiper组件 swiper 滑块视图容器. indicator-dots 是否显示面板指示点 false indicator-color 指示点颜色 indica ...
随机推荐
- 老母鸡安装mqtt
大佬写好了, 按部就班操作一下就行了,在hass中添加mqtt可进行测试 玩客云搭建MQTT服务器 - 崔安兵 - 博客园 (cnblogs.com)
- 运行 Java 程序
Java 程序实际上就是我们编译好的 Java 类文件.运行 Java 程序就是运行 Java 类的 main 函数. 编译并运行 Java 文件 源文件: package com.example; ...
- 【合合TextIn】深度解析智能文档处理技术与应用
一.智能文档处理介绍 智能文档处理(Intelligent Document Processing, IDP)是利用人工智能(AI).机器学习(ML).计算机视觉(CV).自然语言处理(NLP)等技术 ...
- CSS & JS Effect – Styling Input Radio
原生 Radio 的 Limitation <input type="radio" style="width: 25px; height: 25px; cursor ...
- HTML——简介-入门
W3C标准:网页主要由三部分组成 结构:HTML 表现:CSS 行为:JavaScript HTML快速入门 1.新建文本文件,后缀改为 .html 2.编写HTML结构标签(不区分大小写) ...
- [29] CSP模拟2
A.不相邻集合 考虑值域上连续的段,可以发现连续的长度为 \(x\) 的段的贡献必定为 \(\lceil{\frac{x}{2}}\rceil\) 考虑并查集维护值域连续的段的大小,每次询问求出全部连 ...
- 6How To Use Messages With Flask - Flask Fridays #6 10:43
消息闪现 消息闪现 {% for message in get_flashed_messages() %} <div class="alert alert-success alert ...
- Maya 2019.2 Mtoa 无法正常加载并报错
事件起因: 在开始安装 Maya2019.2 时自动安装的 Mtoa 的版本为 5.3.1,但是在插件管理器里无法启用插件,于是乎去网上下了一个低的版本 5.1.1,虽然可以使用但是渲染出来的东西不能 ...
- (系列五).net8 中使用Dapper搭建底层仓储连接数据库(附源码)
说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...
- /proc/pagetypeinfo
这个文件是将buddyinfo的内容进一步细分: Free pages count per migrate type at order -- 不同order 按照migrate type的空闲page ...