human/src/result.ts

195 lines
7.0 KiB
TypeScript
Raw Normal View History

2021-05-25 14:58:20 +02:00
/**
2021-05-31 00:45:39 +02:00
* Type definitions for Human result object
2021-05-25 14:58:20 +02:00
*/
2021-06-03 15:41:53 +02:00
import { Tensor } from './tfjs/types';
2021-07-29 17:01:50 +02:00
import { FaceGesture, BodyGesture, HandGesture, IrisGesture } from './gesture/gesture';
2021-05-22 18:33:19 +02:00
/** Face results
* Combined results of face detector, face mesh, age, gender, emotion, embedding, iris models
* Some values may be null if specific model is not enabled
*
* Each result has:
* - id: face id number
* - score: overal detection confidence score value
* - boxScore: face box detection confidence score value
* - faceScore: face keypoints detection confidence score value
2021-05-22 18:33:19 +02:00
* - box: face bounding box as array of [x, y, width, height], normalized to image resolution
* - boxRaw: face bounding box as array of [x, y, width, height], normalized to range 0..1
* - mesh: face keypoints as array of [x, y, z] points of face mesh, normalized to image resolution
* - meshRaw: face keypoints as array of [x, y, z] points of face mesh, normalized to range 0..1
* - annotations: annotated face keypoints as array of annotated face mesh points
* - age: age as value
* - gender: gender as value
* - genderScore: gender detection confidence score as value
2021-05-22 18:33:19 +02:00
* - emotion: emotions as array of possible emotions with their individual scores
* - embedding: facial descriptor as array of numerical elements
2021-05-24 13:18:03 +02:00
* - iris: iris distance from current viewpoint as distance value in centimeters for a typical camera
* field of view of 88 degrees. value should be adjusted manually as needed
2021-05-22 18:33:19 +02:00
* - rotation: face rotiation that contains both angles and matrix used for 3d transformations
* - angle: face angle as object with values for roll, yaw and pitch angles
* - matrix: 3d transofrmation matrix as array of numeric values
* - gaze: gaze direction as object with values for bearing in radians and relative strength
2021-05-22 18:33:19 +02:00
* - tensor: face tensor as Tensor object which contains detected face
*/
export interface Face {
id: number
score: number,
boxScore: number,
faceScore: number,
2021-05-22 18:33:19 +02:00
box: [number, number, number, number],
boxRaw: [number, number, number, number],
mesh: Array<[number, number, number]>
meshRaw: Array<[number, number, number]>
annotations: Record<string, Array<[number, number, number]>>,
age?: number,
gender?: string,
genderScore?: number,
emotion?: Array<{ score: number, emotion: string }>,
embedding?: Array<number>,
iris?: number,
rotation?: {
2021-05-22 18:33:19 +02:00
angle: { roll: number, yaw: number, pitch: number },
matrix: [number, number, number, number, number, number, number, number, number],
gaze: { bearing: number, strength: number },
2021-05-22 18:33:19 +02:00
}
2021-08-12 00:59:02 +02:00
tensor?: Tensor,
2021-05-22 18:33:19 +02:00
}
/** Body results
*
* Each results has:
* - id: body id number
2021-05-22 18:33:19 +02:00
* - score: overall detection score
* - box: bounding box: x, y, width, height normalized to input image resolution
* - boxRaw: bounding box: x, y, width, height normalized to 0..1
* - keypoints: array of keypoints
* - part: body part name
* - position: body part position with x,y,z coordinates
* - score: body part score value
* - presence: body part presence value
*/
export interface Body {
id: number,
score: number,
box: [number, number, number, number],
boxRaw: [number, number, number, number],
2021-05-22 18:33:19 +02:00
keypoints: Array<{
2021-03-18 01:16:40 +01:00
part: string,
position: [number, number, number?],
positionRaw: [number, number, number?],
2021-03-18 01:16:40 +01:00
score: number,
2021-05-22 19:17:07 +02:00
presence?: number,
2021-05-22 18:33:19 +02:00
}>
}
/** Hand results
*
* Each result has:
* - id: hand id number
* - score: detection confidence score as value
* - box: bounding box: x, y, width, height normalized to input image resolution
* - boxRaw: bounding box: x, y, width, height normalized to 0..1
* - keypoints: keypoints as array of [x, y, z] points of hand, normalized to image resolution
* - annotations: annotated landmarks for each hand part with keypoints
* - landmarks: annotated landmarks for eachb hand part with logical curl and direction strings
2021-05-22 18:33:19 +02:00
*/
export interface Hand {
id: number,
score: number,
2021-05-22 18:33:19 +02:00
box: [number, number, number, number],
boxRaw: [number, number, number, number],
keypoints: Array<[number, number, number]>,
annotations: Record<
'index' | 'middle' | 'pinky' | 'ring' | 'thumb' | 'palm',
Array<[number, number, number]>
>,
landmarks: Record<
'index' | 'middle' | 'pinky' | 'ring' | 'thumb',
{ curl: 'none' | 'half' | 'full', direction: 'verticalUp' | 'verticalDown' | 'horizontalLeft' | 'horizontalRight' | 'diagonalUpRight' | 'diagonalUpLeft' | 'diagonalDownRight' | 'diagonalDownLeft' }
>,
2021-05-22 18:33:19 +02:00
}
/** Object results
*
* Array of individual results with one object per detected gesture
* Each result has:
* - id: object id number
2021-05-22 18:33:19 +02:00
* - score as value
* - label as detected class name
* - box: bounding box: x, y, width, height normalized to input image resolution
* - boxRaw: bounding box: x, y, width, height normalized to 0..1
* - center: optional center point as array of [x, y], normalized to image resolution
* - centerRaw: optional center point as array of [x, y], normalized to range 0..1
2021-05-22 18:33:19 +02:00
*/
export interface Item {
2021-05-24 13:16:38 +02:00
id: number,
2021-05-22 18:33:19 +02:00
score: number,
class: number,
label: string,
box: [number, number, number, number],
boxRaw: [number, number, number, number],
2021-05-22 18:33:19 +02:00
}
/** Gesture results
* @typedef Gesture Type
2021-05-22 18:33:19 +02:00
*
* Array of individual results with one object per detected gesture
* Each result has:
* - part: part name and number where gesture was detected: face, iris, body, hand
* - gesture: gesture detected
*/
export type Gesture =
2021-07-29 17:01:50 +02:00
{ 'face': number, gesture: FaceGesture }
| { 'iris': number, gesture: IrisGesture }
| { 'body': number, gesture: BodyGesture }
| { 'hand': number, gesture: HandGesture }
2021-05-22 18:33:19 +02:00
/** Person getter
* @interface Person Interface
*
* Each result has:
* - id: person id
* - face: face object
* - body: body object
* - hands: array of hand objects
* - gestures: array of gestures
* - box: bounding box: x, y, width, height normalized to input image resolution
* - boxRaw: bounding box: x, y, width, height normalized to 0..1
*/
export interface Person {
id: number,
face: Face,
body: Body | null,
hands: { left: Hand | null, right: Hand | null },
gestures: Array<Gesture>,
box: [number, number, number, number],
boxRaw?: [number, number, number, number],
}
2021-05-24 13:16:38 +02:00
/**
* Result interface definition for **Human** library
*
* Contains all possible detection results
*/
2021-05-22 18:33:19 +02:00
export interface Result {
/** {@link Face}: detection & analysis results */
face: Array<Face>,
/** {@link Body}: detection & analysis results */
body: Array<Body>,
/** {@link Hand}: detection & analysis results */
hand: Array<Hand>,
/** {@link Gesture}: detection & analysis results */
gesture: Array<Gesture>,
/** {@link Object}: detection & analysis results */
object: Array<Item>
/** global performance object with timing values for each operation */
performance: Record<string, unknown>,
/** optional processed canvas that can be used to draw input on screen */
2021-06-04 19:51:01 +02:00
canvas?: OffscreenCanvas | HTMLCanvasElement,
/** timestamp of detection representing the milliseconds elapsed since the UNIX epoch */
readonly timestamp: number,
/** getter property that returns unified persons object */
2021-05-25 14:58:20 +02:00
persons: Array<Person>,
2021-03-17 23:23:19 +01:00
}