- 页面:pose-hub 选择动作,pose-coach 跟练(教练小甄示范 + 摄像头动作识别计数) - 动作:徒手深蹲、原地高抬腿、低冲击开合、站姿侧平举 - VisionKit 人体识别,按动作幅度计数、评分、纠错;没有摄像头或识别不可用时自动进入领练模式 - 教练逐帧动画:分包内置 600px 帧,COS 高清帧全部加载完后无缝切换 - 语音报数与口令(WechatSI),舒缓背景音乐(COS,教练说话时自动压低,可关闭) - 逻辑单测:npm run test:pose
27 lines
967 B
TypeScript
27 lines
967 B
TypeScript
/**
|
||
* 摄像头帧坐标 → 屏幕坐标
|
||
*
|
||
* 识别出的关键点是相对摄像头帧归一化的 [0,1] 坐标;<camera> 预览按 aspectFill 铺满显示区域(裁掉多出的部分),
|
||
* 前置摄像头的预览是镜像的。纠正动作时在画面上标出关节,需要用它换算位置。
|
||
*/
|
||
import type { Point } from './keypoints.ts'
|
||
|
||
export type Viewport = {
|
||
/** 显示区域尺寸(px) */
|
||
width: number
|
||
height: number
|
||
/** 摄像头帧尺寸 */
|
||
frameWidth: number
|
||
frameHeight: number
|
||
/** 预览是否镜像 */
|
||
mirror: boolean
|
||
}
|
||
|
||
export function toScreen(p: Point, vp: Viewport): Point {
|
||
const scale = Math.max(vp.width / vp.frameWidth, vp.height / vp.frameHeight)
|
||
const ox = (vp.width - vp.frameWidth * scale) / 2
|
||
const oy = (vp.height - vp.frameHeight * scale) / 2
|
||
const x = vp.mirror ? 1 - p.x : p.x
|
||
return { x: ox + x * vp.frameWidth * scale, y: oy + p.y * vp.frameHeight * scale }
|
||
}
|