Browse Source

finish INDEX_AND_THUMB_UP

finalv1
Backpack 2 months ago
parent
commit
2d3fbfc4e8
2 changed files with 17 additions and 4 deletions
  1. +10
    -3
      src/hand_landmark/detector.ts
  2. +7
    -1
      wavecontrol-test/src/hand_landmark/detector.ts

+ 10
- 3
src/hand_landmark/detector.ts View File

@ -7,6 +7,7 @@ import {
export enum HandGesture {
// 食指举起,移动鼠标
ONLY_INDEX_UP = "only_index_up",
INDEX_AND_THUMB_UP = "index_and_thumb_up"
}
interface HandLandmark {
@ -148,6 +149,8 @@ export class Detector {
const gestureMap = new Map<string, HandGesture>([
// 食指举起,移动鼠标
["0,1,0,0,0", HandGesture.ONLY_INDEX_UP],
// 鼠标左键点击手势
["1,1,0,0,0", HandGesture.INDEX_AND_THUMB_UP],
]);
if (gestureMap.has(fingerState)) {
@ -166,15 +169,19 @@ export class Detector {
const hand = detection.rightHand ?? detection.leftHand;
if (!hand) {
console.log("没检测到手");
console.log("没检测到手");
return HandGesture.OTHER;
}
const gesture = Detector.getSingleHandGesture(hand);
console.log("🎯 当前手势状态是:", gesture);
console.log("当前手势状态是:", gesture);
if (gesture === HandGesture.ONLY_INDEX_UP) {
console.log("✅ 识别到食指竖起!");
console.log("识别到食指竖起!");
}
if (gesture === HandGesture.INDEX_AND_THUMB_UP) {
console.log("识别到食指和大拇指竖起!");
}
return gesture;

+ 7
- 1
wavecontrol-test/src/hand_landmark/detector.ts View File

@ -7,6 +7,7 @@ import {
export enum HandGesture {
// 食指举起,移动鼠标
ONLY_INDEX_UP = "only_index_up",
INDEX_AND_THUMB_UP = "index_and_thumb_up"
}
interface HandLandmark {
@ -103,7 +104,6 @@ export class Detector {
return detection;
}
/**
*
*/
@ -149,6 +149,8 @@ export class Detector {
const gestureMap = new Map<string, HandGesture>([
// 食指举起,移动鼠标
["0,1,0,0,0", HandGesture.ONLY_INDEX_UP],
// 鼠标左键点击手势
["1,1,0,0,0", HandGesture.INDEX_AND_THUMB_UP],
]);
if (gestureMap.has(fingerState)) {
@ -178,6 +180,10 @@ export class Detector {
console.log("识别到食指竖起!");
}
if (gesture === HandGesture.INDEX_AND_THUMB_UP) {
console.log("识别到食指和大拇指竖起!");
}
return gesture;
}

Loading…
Cancel
Save