rtmlib-ts 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/README.md +202 -0
- package/dist/core/base.d.ts +20 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/base.js +40 -0
- package/dist/core/file.d.ts +11 -0
- package/dist/core/file.d.ts.map +1 -0
- package/dist/core/file.js +111 -0
- package/dist/core/modelCache.d.ts +35 -0
- package/dist/core/modelCache.d.ts.map +1 -0
- package/dist/core/modelCache.js +161 -0
- package/dist/core/posePostprocessing.d.ts +12 -0
- package/dist/core/posePostprocessing.d.ts.map +1 -0
- package/dist/core/posePostprocessing.js +76 -0
- package/dist/core/postprocessing.d.ts +10 -0
- package/dist/core/postprocessing.d.ts.map +1 -0
- package/dist/core/postprocessing.js +70 -0
- package/dist/core/preprocessing.d.ts +14 -0
- package/dist/core/preprocessing.d.ts.map +1 -0
- package/dist/core/preprocessing.js +79 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/models/rtmpose.d.ts +25 -0
- package/dist/models/rtmpose.d.ts.map +1 -0
- package/dist/models/rtmpose.js +185 -0
- package/dist/models/rtmpose3d.d.ts +28 -0
- package/dist/models/rtmpose3d.d.ts.map +1 -0
- package/dist/models/rtmpose3d.js +184 -0
- package/dist/models/yolo12.d.ts +23 -0
- package/dist/models/yolo12.d.ts.map +1 -0
- package/dist/models/yolo12.js +165 -0
- package/dist/models/yolox.d.ts +18 -0
- package/dist/models/yolox.d.ts.map +1 -0
- package/dist/models/yolox.js +167 -0
- package/dist/solution/animalDetector.d.ts +229 -0
- package/dist/solution/animalDetector.d.ts.map +1 -0
- package/dist/solution/animalDetector.js +663 -0
- package/dist/solution/body.d.ts +16 -0
- package/dist/solution/body.d.ts.map +1 -0
- package/dist/solution/body.js +52 -0
- package/dist/solution/bodyWithFeet.d.ts +16 -0
- package/dist/solution/bodyWithFeet.d.ts.map +1 -0
- package/dist/solution/bodyWithFeet.js +52 -0
- package/dist/solution/customDetector.d.ts +137 -0
- package/dist/solution/customDetector.d.ts.map +1 -0
- package/dist/solution/customDetector.js +342 -0
- package/dist/solution/hand.d.ts +14 -0
- package/dist/solution/hand.d.ts.map +1 -0
- package/dist/solution/hand.js +20 -0
- package/dist/solution/index.d.ts +10 -0
- package/dist/solution/index.d.ts.map +1 -0
- package/dist/solution/index.js +9 -0
- package/dist/solution/objectDetector.d.ts +172 -0
- package/dist/solution/objectDetector.d.ts.map +1 -0
- package/dist/solution/objectDetector.js +606 -0
- package/dist/solution/pose3dDetector.d.ts +145 -0
- package/dist/solution/pose3dDetector.d.ts.map +1 -0
- package/dist/solution/pose3dDetector.js +611 -0
- package/dist/solution/poseDetector.d.ts +198 -0
- package/dist/solution/poseDetector.d.ts.map +1 -0
- package/dist/solution/poseDetector.js +622 -0
- package/dist/solution/poseTracker.d.ts +22 -0
- package/dist/solution/poseTracker.d.ts.map +1 -0
- package/dist/solution/poseTracker.js +106 -0
- package/dist/solution/wholebody.d.ts +19 -0
- package/dist/solution/wholebody.d.ts.map +1 -0
- package/dist/solution/wholebody.js +82 -0
- package/dist/solution/wholebody3d.d.ts +22 -0
- package/dist/solution/wholebody3d.d.ts.map +1 -0
- package/dist/solution/wholebody3d.js +75 -0
- package/dist/types/index.d.ts +52 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/visualization/draw.d.ts +57 -0
- package/dist/visualization/draw.d.ts.map +1 -0
- package/dist/visualization/draw.js +400 -0
- package/dist/visualization/skeleton/coco133.d.ts +350 -0
- package/dist/visualization/skeleton/coco133.d.ts.map +1 -0
- package/dist/visualization/skeleton/coco133.js +120 -0
- package/dist/visualization/skeleton/coco17.d.ts +180 -0
- package/dist/visualization/skeleton/coco17.d.ts.map +1 -0
- package/dist/visualization/skeleton/coco17.js +48 -0
- package/dist/visualization/skeleton/halpe26.d.ts +278 -0
- package/dist/visualization/skeleton/halpe26.d.ts.map +1 -0
- package/dist/visualization/skeleton/halpe26.js +70 -0
- package/dist/visualization/skeleton/hand21.d.ts +196 -0
- package/dist/visualization/skeleton/hand21.d.ts.map +1 -0
- package/dist/visualization/skeleton/hand21.js +51 -0
- package/dist/visualization/skeleton/index.d.ts +10 -0
- package/dist/visualization/skeleton/index.d.ts.map +1 -0
- package/dist/visualization/skeleton/index.js +9 -0
- package/dist/visualization/skeleton/openpose134.d.ts +357 -0
- package/dist/visualization/skeleton/openpose134.d.ts.map +1 -0
- package/dist/visualization/skeleton/openpose134.js +116 -0
- package/dist/visualization/skeleton/openpose18.d.ts +177 -0
- package/dist/visualization/skeleton/openpose18.d.ts.map +1 -0
- package/dist/visualization/skeleton/openpose18.js +47 -0
- package/docs/ANIMAL_DETECTOR.md +450 -0
- package/docs/CUSTOM_DETECTOR.md +568 -0
- package/docs/OBJECT_DETECTOR.md +373 -0
- package/docs/POSE3D_DETECTOR.md +458 -0
- package/docs/POSE_DETECTOR.md +442 -0
- package/examples/README.md +119 -0
- package/examples/index.html +746 -0
- package/package.json +51 -0
- package/playground/README.md +114 -0
- package/playground/app/favicon.ico +0 -0
- package/playground/app/globals.css +17 -0
- package/playground/app/layout.tsx +19 -0
- package/playground/app/page.tsx +1338 -0
- package/playground/eslint.config.mjs +18 -0
- package/playground/next.config.ts +34 -0
- package/playground/package-lock.json +6723 -0
- package/playground/package.json +27 -0
- package/playground/postcss.config.mjs +7 -0
- package/playground/tsconfig.json +34 -0
- package/src/core/base.ts +66 -0
- package/src/core/file.ts +141 -0
- package/src/core/modelCache.ts +189 -0
- package/src/core/posePostprocessing.ts +91 -0
- package/src/core/postprocessing.ts +93 -0
- package/src/core/preprocessing.ts +127 -0
- package/src/index.ts +69 -0
- package/src/models/rtmpose.ts +265 -0
- package/src/models/rtmpose3d.ts +289 -0
- package/src/models/yolo12.ts +220 -0
- package/src/models/yolox.ts +214 -0
- package/src/solution/animalDetector.ts +955 -0
- package/src/solution/body.ts +89 -0
- package/src/solution/bodyWithFeet.ts +89 -0
- package/src/solution/customDetector.ts +474 -0
- package/src/solution/hand.ts +52 -0
- package/src/solution/index.ts +10 -0
- package/src/solution/objectDetector.ts +816 -0
- package/src/solution/pose3dDetector.ts +890 -0
- package/src/solution/poseDetector.ts +892 -0
- package/src/solution/poseTracker.ts +172 -0
- package/src/solution/wholebody.ts +130 -0
- package/src/solution/wholebody3d.ts +125 -0
- package/src/types/index.ts +62 -0
- package/src/visualization/draw.ts +543 -0
- package/src/visualization/skeleton/coco133.ts +131 -0
- package/src/visualization/skeleton/coco17.ts +49 -0
- package/src/visualization/skeleton/halpe26.ts +71 -0
- package/src/visualization/skeleton/hand21.ts +52 -0
- package/src/visualization/skeleton/index.ts +10 -0
- package/src/visualization/skeleton/openpose134.ts +125 -0
- package/src/visualization/skeleton/openpose18.ts +48 -0
- package/tsconfig.json +32 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectDetector - Universal object detection API
|
|
3
|
+
* Supports YOLO12 and other YOLO models for multi-class detection
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // Initialize with default model (YOLOv12n from HuggingFace)
|
|
8
|
+
* const detector = new ObjectDetector({
|
|
9
|
+
* classes: ['person', 'car', 'dog'], // Filter specific classes
|
|
10
|
+
* });
|
|
11
|
+
* await detector.init();
|
|
12
|
+
*
|
|
13
|
+
* // Or with custom model
|
|
14
|
+
* const detector = new ObjectDetector({
|
|
15
|
+
* model: 'models/yolov12n.onnx',
|
|
16
|
+
* classes: ['person'],
|
|
17
|
+
* });
|
|
18
|
+
* await detector.init();
|
|
19
|
+
*
|
|
20
|
+
* // Detect from canvas
|
|
21
|
+
* const objects = await detector.detectFromCanvas(canvas);
|
|
22
|
+
*
|
|
23
|
+
* // Detect all classes
|
|
24
|
+
* const allObjects = await detector.detectFromCanvas(canvas, { classes: null });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* COCO 80-class names
|
|
29
|
+
*/
|
|
30
|
+
export declare const COCO_CLASSES: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Configuration options for ObjectDetector
|
|
33
|
+
*/
|
|
34
|
+
export interface ObjectDetectorConfig {
|
|
35
|
+
/** Path to YOLO detection model (optional - uses default YOLOv12n from HuggingFace if not specified) */
|
|
36
|
+
model?: string;
|
|
37
|
+
/** Input size (default: [416, 416] for speed) */
|
|
38
|
+
inputSize?: [number, number];
|
|
39
|
+
/** Confidence threshold (default: 0.5) */
|
|
40
|
+
confidence?: number;
|
|
41
|
+
/** NMS IoU threshold (default: 0.45) */
|
|
42
|
+
nmsThreshold?: number;
|
|
43
|
+
/** Classes to detect (null = all, default: ['person']) */
|
|
44
|
+
classes?: string[] | null;
|
|
45
|
+
/** Execution backend (default: 'wasm') */
|
|
46
|
+
backend?: 'wasm' | 'webgpu';
|
|
47
|
+
/** Performance mode (default: 'balanced') */
|
|
48
|
+
mode?: 'performance' | 'balanced' | 'lightweight';
|
|
49
|
+
/** Device type (for future use) */
|
|
50
|
+
device?: 'cpu' | 'gpu';
|
|
51
|
+
/** Enable model caching (default: true) */
|
|
52
|
+
cache?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Detected object with bounding box and class
|
|
56
|
+
*/
|
|
57
|
+
export interface DetectedObject {
|
|
58
|
+
/** Bounding box coordinates */
|
|
59
|
+
bbox: {
|
|
60
|
+
x1: number;
|
|
61
|
+
y1: number;
|
|
62
|
+
x2: number;
|
|
63
|
+
y2: number;
|
|
64
|
+
confidence: number;
|
|
65
|
+
};
|
|
66
|
+
/** Class ID (0-79 for COCO) */
|
|
67
|
+
classId: number;
|
|
68
|
+
/** Class name */
|
|
69
|
+
className: string;
|
|
70
|
+
/** Detection confidence (0-1) */
|
|
71
|
+
confidence: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Detection statistics
|
|
75
|
+
*/
|
|
76
|
+
export interface DetectionStats {
|
|
77
|
+
/** Total number of detections */
|
|
78
|
+
totalCount: number;
|
|
79
|
+
/** Detections per class */
|
|
80
|
+
classCounts: Record<string, number>;
|
|
81
|
+
/** Inference time (ms) */
|
|
82
|
+
inferenceTime: number;
|
|
83
|
+
}
|
|
84
|
+
export declare class ObjectDetector {
|
|
85
|
+
private config;
|
|
86
|
+
private session;
|
|
87
|
+
private initialized;
|
|
88
|
+
private classFilter;
|
|
89
|
+
private canvas;
|
|
90
|
+
private ctx;
|
|
91
|
+
private tensorBuffer;
|
|
92
|
+
private inputSize;
|
|
93
|
+
constructor(config: ObjectDetectorConfig);
|
|
94
|
+
/**
|
|
95
|
+
* Update class filter based on config
|
|
96
|
+
*/
|
|
97
|
+
private updateClassFilter;
|
|
98
|
+
/**
|
|
99
|
+
* Set which classes to detect
|
|
100
|
+
* @param classes - Array of class names or null for all classes
|
|
101
|
+
*/
|
|
102
|
+
setClasses(classes: string[] | null): void;
|
|
103
|
+
/**
|
|
104
|
+
* Get list of available COCO classes
|
|
105
|
+
*/
|
|
106
|
+
getAvailableClasses(): string[];
|
|
107
|
+
/**
|
|
108
|
+
* Get currently filtered classes
|
|
109
|
+
*/
|
|
110
|
+
getFilteredClasses(): string[] | null;
|
|
111
|
+
/**
|
|
112
|
+
* Initialize detection model and pre-allocate resources
|
|
113
|
+
*/
|
|
114
|
+
init(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Detect objects from HTMLCanvasElement
|
|
117
|
+
*/
|
|
118
|
+
detectFromCanvas(canvas: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Detect objects from HTMLVideoElement
|
|
121
|
+
*/
|
|
122
|
+
detectFromVideo(video: HTMLVideoElement, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Detect objects from HTMLImageElement
|
|
125
|
+
*/
|
|
126
|
+
detectFromImage(image: HTMLImageElement, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Detect objects from ImageBitmap
|
|
129
|
+
*/
|
|
130
|
+
detectFromBitmap(bitmap: ImageBitmap, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Detect objects from File
|
|
133
|
+
*/
|
|
134
|
+
detectFromFile(file: File, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Detect objects from Blob
|
|
137
|
+
*/
|
|
138
|
+
detectFromBlob(blob: Blob, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Detect objects from raw image data
|
|
141
|
+
*/
|
|
142
|
+
detect(imageData: Uint8Array, width: number, height: number): Promise<DetectedObject[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Optimized preprocess with resource reuse
|
|
145
|
+
*/
|
|
146
|
+
private preprocess;
|
|
147
|
+
/**
|
|
148
|
+
* Postprocess YOLO output - supports multiple output formats
|
|
149
|
+
*/
|
|
150
|
+
private postprocess;
|
|
151
|
+
/**
|
|
152
|
+
* Multi-class Non-Maximum Suppression
|
|
153
|
+
*/
|
|
154
|
+
private applyMultiClassNMS;
|
|
155
|
+
/**
|
|
156
|
+
* Calculate IoU between two boxes
|
|
157
|
+
*/
|
|
158
|
+
private calculateIoU;
|
|
159
|
+
/**
|
|
160
|
+
* Calculate detection statistics
|
|
161
|
+
*/
|
|
162
|
+
private calculateStats;
|
|
163
|
+
/**
|
|
164
|
+
* Get statistics from last detection
|
|
165
|
+
*/
|
|
166
|
+
getStats(): DetectionStats | null;
|
|
167
|
+
/**
|
|
168
|
+
* Dispose resources
|
|
169
|
+
*/
|
|
170
|
+
dispose(): void;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=objectDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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