updated gesture types

pull/356/head
Vladimir Mandic 2021-07-29 11:01:50 -04:00
parent fbe8a8b0f6
commit e84e421a04
5 changed files with 51 additions and 18 deletions

View File

@ -26,6 +26,7 @@
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-var-requires": "off",
"camelcase": "off",
"dot-notation": "off",
@ -44,6 +45,7 @@
"no-bitwise": "off",
"no-case-declarations":"off",
"no-continue": "off",
"no-lonely-if": "off",
"no-loop-func": "off",
"no-mixed-operators": "off",
"no-param-reassign":"off",
@ -52,12 +54,12 @@
"no-restricted-globals": "off",
"no-restricted-syntax": "off",
"no-return-assign": "off",
"no-shadow": "off",
"no-underscore-dangle": "off",
"node/no-missing-import": ["error", { "tryExtensions": [".js", ".json", ".ts"] }],
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off",
"node/no-unsupported-features/es-syntax": "off",
"no-lonely-if": "off",
"node/shebang": "off",
"object-curly-newline": "off",
"prefer-destructuring": "off",

View File

@ -9,7 +9,10 @@ Repository: **<git+https://github.com/vladmandic/human.git>**
## Changelog
### **HEAD -> main** 2021/07/19 marcogodoy@untitled.cl
### **HEAD -> main** 2021/07/29 mandic00@live.com
### **origin/main** 2021/07/19 marcogodoy@untitled.cl
- add note on manually disping tensor
- modularize model loading

View File

@ -4,9 +4,41 @@
import { Gesture } from '../result';
/**
* @typedef FaceGesture
*/
export type FaceGesture =
`facing ${'left' | 'center' | 'right'}`
| `blink ${'left' | 'right'} eye`
| `mouth ${number}% open`
| `head ${'up' | 'down'}`;
/**
* @typedef IrisGesture
*/
export type IrisGesture =
'facing center'
| `looking ${'left' | 'right' | 'up' | 'down'}`
| 'looking center';
/**
* @typedef BodyGesture
*/
export type BodyGesture =
`leaning ${'left' | 'right'}`
| `raise ${'left' | 'right'} hand`
| 'i give up';
/**
* @typedef BodyGesture
*/
export type HandGesture =
`${'thumb' | 'index finger' | 'middle finger' | 'ring finger' | 'pinky'} forward`
| `${'thumb' | 'index finger' | 'middle finger' | 'ring finger' | 'pinky'} up`;
export const body = (res): Gesture[] => {
if (!res) return [];
const gestures: Array<{ body: number, gesture: string }> = [];
const gestures: Array<{ body: number, gesture: BodyGesture }> = [];
for (let i = 0; i < res.length; i++) {
// raising hands
const leftWrist = res[i].keypoints.find((a) => (a.part === 'leftWrist'));
@ -26,7 +58,7 @@ export const body = (res): Gesture[] => {
export const face = (res): Gesture[] => {
if (!res) return [];
const gestures: Array<{ face: number, gesture: string }> = [];
const gestures: Array<{ face: number, gesture: FaceGesture }> = [];
for (let i = 0; i < res.length; i++) {
if (res[i].mesh && res[i].mesh.length > 0) {
const eyeFacing = res[i].mesh[33][2] - res[i].mesh[263][2];
@ -47,7 +79,7 @@ export const face = (res): Gesture[] => {
export const iris = (res): Gesture[] => {
if (!res) return [];
const gestures: Array<{ iris: number, gesture: string }> = [];
const gestures: Array<{ iris: number, gesture: IrisGesture }> = [];
for (let i = 0; i < res.length; i++) {
if (!res[i].annotations || !res[i].annotations.leftEyeIris || !res[i].annotations.rightEyeIris) continue;
const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0];
@ -85,7 +117,7 @@ export const iris = (res): Gesture[] => {
export const hand = (res): Gesture[] => {
if (!res) return [];
const gestures: Array<{ hand: number, gesture: string }> = [];
const gestures: Array<{ hand: number, gesture: HandGesture }> = [];
for (let i = 0; i < res.length; i++) {
const fingers: Array<{ name: string, position: number }> = [];
for (const [finger, pos] of Object.entries(res[i]['annotations'])) {
@ -93,8 +125,9 @@ export const hand = (res): Gesture[] => {
}
if (fingers && fingers.length > 0) {
const closest = fingers.reduce((best, a) => (best.position[2] < a.position[2] ? best : a));
gestures.push({ hand: i, gesture: `${closest.name} forward` as HandGesture });
const highest = fingers.reduce((best, a) => (best.position[1] < a.position[1] ? best : a));
gestures.push({ hand: i, gesture: `${closest.name} forward ${highest.name} up` });
gestures.push({ hand: i, gesture: `${highest.name} up` as HandGesture });
}
}
return gestures;

View File

@ -3,6 +3,7 @@
*/
import { Tensor } from './tfjs/types';
import { FaceGesture, BodyGesture, HandGesture, IrisGesture } from './gesture/gesture';
/** Face results
* Combined results of face detector, face mesh, age, gender, emotion, embedding, iris models
@ -132,10 +133,10 @@ export interface Item {
* - gesture: gesture detected
*/
export type Gesture =
{ 'face': number, gesture: string }
| { 'iris': number, gesture: string }
| { 'body': number, gesture: string }
| { 'hand': number, gesture: string }
{ 'face': number, gesture: FaceGesture }
| { 'iris': number, gesture: IrisGesture }
| { 'body': number, gesture: BodyGesture }
| { 'hand': number, gesture: HandGesture }
/** Person getter
* @interface Person Interface

View File

@ -10,13 +10,7 @@ Not required for normal funcioning of library
- Face rotation is disabled for `NodeJS` platform:
`Kernel 'RotateWithOffset' not registered for backend 'tensorflow'`
<https://github.com/tensorflow/tfjs/issues/4606>
### NodeJS with GPU acceleation using CUDA
- Image filters are disabled due to lack of Canvas and WeBGL access
- Face rotation is disabled for `NodeJS` platform:
`Kernel 'RotateWithOffset' not registered for backend 'tensorflow'`
<https://github.com/tensorflow/tfjs/issues/4606>
Work has recently been completed and will likely be included in TFJS 3.9.0
### NodeJS using WASM