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,373 @@
|
|
|
1
|
+
# ObjectDetector API
|
|
2
|
+
|
|
3
|
+
Universal multi-class object detection API supporting all 80 COCO classes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`ObjectDetector` provides a simple, unified interface for detecting objects in images, videos, and live camera feeds. Supports YOLO12 and other YOLO models.
|
|
8
|
+
|
|
9
|
+
**Model is loaded automatically from HuggingFace if not specified.**
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install rtmlib-ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Default Model (Auto-loaded)
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ObjectDetector } from 'rtmlib-ts';
|
|
23
|
+
|
|
24
|
+
// Initialize with default model from HuggingFace
|
|
25
|
+
const detector = new ObjectDetector({
|
|
26
|
+
classes: ['person', 'car'], // Optional: filter classes
|
|
27
|
+
});
|
|
28
|
+
await detector.init();
|
|
29
|
+
|
|
30
|
+
const objects = await detector.detectFromCanvas(canvas);
|
|
31
|
+
console.log(`Found ${objects.length} objects`);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Detect People (Default)
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { ObjectDetector } from 'rtmlib-ts';
|
|
38
|
+
|
|
39
|
+
const detector = new ObjectDetector({
|
|
40
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx', // Path to model file
|
|
41
|
+
});
|
|
42
|
+
await detector.init();
|
|
43
|
+
|
|
44
|
+
const objects = await detector.detectFromCanvas(canvas);
|
|
45
|
+
console.log(`Found ${objects.length} objects`);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Detect Multiple Classes
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const detector = new ObjectDetector({
|
|
52
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
53
|
+
classes: ['person', 'car', 'dog'], // Only detect these
|
|
54
|
+
});
|
|
55
|
+
await detector.init();
|
|
56
|
+
|
|
57
|
+
const objects = await detector.detectFromCanvas(canvas);
|
|
58
|
+
// Only person, car, and dog detections
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Detect All Classes
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const detector = new ObjectDetector({
|
|
65
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
66
|
+
classes: null, // Detect all 80 COCO classes
|
|
67
|
+
});
|
|
68
|
+
await detector.init();
|
|
69
|
+
|
|
70
|
+
const objects = await detector.detectFromCanvas(canvas);
|
|
71
|
+
objects.forEach(obj => {
|
|
72
|
+
console.log(`${obj.className}: ${(obj.confidence * 100).toFixed(1)}%`);
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Change Classes Dynamically
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Start with person detection
|
|
80
|
+
const detector = new ObjectDetector({
|
|
81
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
82
|
+
classes: ['person'],
|
|
83
|
+
});
|
|
84
|
+
await detector.init();
|
|
85
|
+
|
|
86
|
+
// Later: detect vehicles only
|
|
87
|
+
detector.setClasses(['car', 'bus', 'truck']);
|
|
88
|
+
|
|
89
|
+
// Detect all classes
|
|
90
|
+
detector.setClasses(null);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### Constructor
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
new ObjectDetector(config?: ObjectDetectorConfig)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Configuration:**
|
|
102
|
+
|
|
103
|
+
| Option | Type | Default | Description |
|
|
104
|
+
|--------|------|---------|-------------|
|
|
105
|
+
| `model` | `string` | optional | Path to YOLO model |
|
|
106
|
+
| `inputSize` | `[number, number]` | `[416, 416]` | Input size |
|
|
107
|
+
| `confidence` | `number` | `0.5` | Confidence threshold |
|
|
108
|
+
| `nmsThreshold` | `number` | `0.45` | NMS IoU threshold |
|
|
109
|
+
| `classes` | `string[] \| null` | `['person']` | Classes to detect |
|
|
110
|
+
| `backend` | `'wasm' \| 'webgpu'` | `'wasm'` | Execution backend |
|
|
111
|
+
| `mode` | `'performance' \| 'balanced' \| 'lightweight'` | `'balanced'` | Performance mode |
|
|
112
|
+
| `cache` | `boolean` | `true` | Enable model caching |
|
|
113
|
+
|
|
114
|
+
### Default Model
|
|
115
|
+
|
|
116
|
+
If `model` is not specified, the following default model is used:
|
|
117
|
+
|
|
118
|
+
- **Model**: `https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx`
|
|
119
|
+
|
|
120
|
+
### Methods
|
|
121
|
+
|
|
122
|
+
#### Detection Methods
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// From canvas
|
|
126
|
+
async detectFromCanvas(canvas: HTMLCanvasElement): Promise<DetectedObject[]>
|
|
127
|
+
|
|
128
|
+
// From video (real-time)
|
|
129
|
+
async detectFromVideo(video: HTMLVideoElement, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>
|
|
130
|
+
|
|
131
|
+
// From image
|
|
132
|
+
async detectFromImage(image: HTMLImageElement, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>
|
|
133
|
+
|
|
134
|
+
// From file upload
|
|
135
|
+
async detectFromFile(file: File, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>
|
|
136
|
+
|
|
137
|
+
// From blob/camera
|
|
138
|
+
async detectFromBlob(blob: Blob, targetCanvas?: HTMLCanvasElement): Promise<DetectedObject[]>
|
|
139
|
+
|
|
140
|
+
// From raw data
|
|
141
|
+
async detect(imageData: Uint8Array, width: number, height: number): Promise<DetectedObject[]>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Class Management
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
// Set classes to detect
|
|
148
|
+
detector.setClasses(['person', 'car']); // Specific classes
|
|
149
|
+
detector.setClasses(null); // All classes
|
|
150
|
+
|
|
151
|
+
// Get available classes
|
|
152
|
+
const allClasses = detector.getAvailableClasses(); // 80 COCO classes
|
|
153
|
+
|
|
154
|
+
// Get current filter
|
|
155
|
+
const current = detector.getFilteredClasses();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Other
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
await detector.init(); // Initialize
|
|
162
|
+
detector.dispose(); // Cleanup
|
|
163
|
+
detector.getStats(); // Get last detection stats
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Types
|
|
167
|
+
|
|
168
|
+
#### `DetectedObject`
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface DetectedObject {
|
|
172
|
+
bbox: {
|
|
173
|
+
x1: number;
|
|
174
|
+
y1: number;
|
|
175
|
+
x2: number;
|
|
176
|
+
y2: number;
|
|
177
|
+
confidence: number;
|
|
178
|
+
};
|
|
179
|
+
classId: number; // 0-79 for COCO
|
|
180
|
+
className: string; // e.g., "person", "car"
|
|
181
|
+
confidence: number; // 0-1
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### `DetectionStats`
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
interface DetectionStats {
|
|
189
|
+
totalCount: number;
|
|
190
|
+
classCounts: Record<string, number>;
|
|
191
|
+
inferenceTime: number;
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## COCO Classes
|
|
196
|
+
|
|
197
|
+
All 80 COCO classes (by ID):
|
|
198
|
+
|
|
199
|
+
| ID | Class | ID | Class |
|
|
200
|
+
|----|-------|----|-------|
|
|
201
|
+
| 0 | person | 40 | cup |
|
|
202
|
+
| 1 | bicycle | 41 | fork |
|
|
203
|
+
| 2 | car | 42 | knife |
|
|
204
|
+
| 3 | motorcycle | 43 | spoon |
|
|
205
|
+
| 4 | airplane | 44 | bowl |
|
|
206
|
+
| 5 | bus | 45 | banana |
|
|
207
|
+
| 6 | train | 46 | apple |
|
|
208
|
+
| 7 | truck | 47 | sandwich |
|
|
209
|
+
| 8 | boat | 48 | orange |
|
|
210
|
+
| 9 | traffic light | 49 | broccoli |
|
|
211
|
+
| 10 | fire hydrant | 50 | carrot |
|
|
212
|
+
| 11 | stop sign | 51 | hot dog |
|
|
213
|
+
| 12 | parking meter | 52 | pizza |
|
|
214
|
+
| 13 | bench | 53 | donut |
|
|
215
|
+
| 14 | bird | 54 | cake |
|
|
216
|
+
| 15 | cat | 55 | chair |
|
|
217
|
+
| 16 | dog | 56 | couch |
|
|
218
|
+
| 17 | horse | 57 | potted plant |
|
|
219
|
+
| 18 | sheep | 58 | bed |
|
|
220
|
+
| 19 | cow | 59 | dining table |
|
|
221
|
+
| 20 | elephant | 60 | toilet |
|
|
222
|
+
| 21 | bear | 61 | tv |
|
|
223
|
+
| 22 | zebra | 62 | laptop |
|
|
224
|
+
| 23 | giraffe | 63 | mouse |
|
|
225
|
+
| 24 | backpack | 64 | remote |
|
|
226
|
+
| 25 | umbrella | 65 | keyboard |
|
|
227
|
+
| 26 | handbag | 66 | cell phone |
|
|
228
|
+
| 27 | tie | 67 | microwave |
|
|
229
|
+
| 28 | suitcase | 68 | oven |
|
|
230
|
+
| 29 | frisbee | 69 | toaster |
|
|
231
|
+
| 30 | skis | 70 | sink |
|
|
232
|
+
| 31 | snowboard | 71 | refrigerator |
|
|
233
|
+
| 32 | sports ball | 72 | book |
|
|
234
|
+
| 33 | kite | 73 | clock |
|
|
235
|
+
| 34 | baseball bat | 74 | vase |
|
|
236
|
+
| 35 | baseball glove | 75 | scissors |
|
|
237
|
+
| 36 | skateboard | 76 | teddy bear |
|
|
238
|
+
| 37 | surfboard | 77 | hair drier |
|
|
239
|
+
| 38 | tennis racket | 78 | toothbrush |
|
|
240
|
+
| 39 | bottle | | |
|
|
241
|
+
|
|
242
|
+
## Examples
|
|
243
|
+
|
|
244
|
+
### Real-time Video Detection
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const video = document.querySelector('video')!;
|
|
248
|
+
const detector = new ObjectDetector({
|
|
249
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
250
|
+
classes: ['person', 'car'],
|
|
251
|
+
});
|
|
252
|
+
await detector.init();
|
|
253
|
+
|
|
254
|
+
async function detectLoop() {
|
|
255
|
+
const objects = await detector.detectFromVideo(video);
|
|
256
|
+
|
|
257
|
+
// Draw detections
|
|
258
|
+
objects.forEach(obj => {
|
|
259
|
+
ctx.strokeStyle = '#00ff00';
|
|
260
|
+
ctx.strokeRect(
|
|
261
|
+
obj.bbox.x1, obj.bbox.y1,
|
|
262
|
+
obj.bbox.x2 - obj.bbox.x1,
|
|
263
|
+
obj.bbox.y2 - obj.bbox.y1
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
requestAnimationFrame(detectLoop);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
video.play();
|
|
271
|
+
detectLoop();
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### File Upload
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
const fileInput = document.querySelector('input[type="file"]')!;
|
|
278
|
+
|
|
279
|
+
fileInput.addEventListener('change', async (e) => {
|
|
280
|
+
const file = (e.target as HTMLInputElement).files?.[0];
|
|
281
|
+
if (!file) return;
|
|
282
|
+
|
|
283
|
+
const objects = await detector.detectFromFile(file);
|
|
284
|
+
console.log(`Found ${objects.length} objects`);
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Camera Capture
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
292
|
+
video: { width: 1280, height: 720 }
|
|
293
|
+
});
|
|
294
|
+
const video = document.querySelector('video')!;
|
|
295
|
+
video.srcObject = stream;
|
|
296
|
+
|
|
297
|
+
video.addEventListener('play', async () => {
|
|
298
|
+
const objects = await detector.detectFromVideo(video);
|
|
299
|
+
|
|
300
|
+
// Get stats
|
|
301
|
+
const stats = (objects as any).stats;
|
|
302
|
+
console.log(`Detected ${stats.totalCount} objects in ${stats.inferenceTime}ms`);
|
|
303
|
+
console.log('By class:', stats.classCounts);
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Performance Optimization
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// Use WebGPU for faster inference
|
|
311
|
+
const detector = new ObjectDetector({
|
|
312
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
313
|
+
backend: 'webgpu', // Faster than WASM
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Smaller input size for speed
|
|
317
|
+
const detector = new ObjectDetector({
|
|
318
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
319
|
+
inputSize: [416, 416], // Faster, less accurate
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Higher confidence threshold
|
|
323
|
+
const detector = new ObjectDetector({
|
|
324
|
+
model: 'https://huggingface.co/demon2233/rtmlib-ts/resolve/main/yolo/yolov12n.onnx',
|
|
325
|
+
confidence: 0.7, // Only high-confidence detections
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Reuse detector instance
|
|
329
|
+
const detector = new ObjectDetector(config);
|
|
330
|
+
await detector.init();
|
|
331
|
+
|
|
332
|
+
// Process multiple frames
|
|
333
|
+
for (const frame of frames) {
|
|
334
|
+
const objects = await detector.detectFromCanvas(frame.canvas);
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Performance
|
|
339
|
+
|
|
340
|
+
Typical inference times (M1 MacBook Pro):
|
|
341
|
+
|
|
342
|
+
| Configuration | Time | Classes |
|
|
343
|
+
|--------------|------|---------|
|
|
344
|
+
| WASM, 640×640 | 80ms | All 80 |
|
|
345
|
+
| WASM, 416×416 | 40ms | All 80 |
|
|
346
|
+
| WebGPU, 640×640 | 30ms | All 80 |
|
|
347
|
+
|
|
348
|
+
## Troubleshooting
|
|
349
|
+
|
|
350
|
+
### "No detections"
|
|
351
|
+
|
|
352
|
+
- Lower `confidence` threshold (try 0.3)
|
|
353
|
+
- Ensure object is visible and large enough
|
|
354
|
+
- Check that class is in COCO dataset
|
|
355
|
+
|
|
356
|
+
### "Unknown class" warning
|
|
357
|
+
|
|
358
|
+
Class names must match COCO exactly:
|
|
359
|
+
- ✅ `'person'`, `'car'`, `'traffic light'`
|
|
360
|
+
- ❌ `'Person'`, `'cars'`, `'traffic_light'`
|
|
361
|
+
|
|
362
|
+
Use `detector.getAvailableClasses()` to see valid names.
|
|
363
|
+
|
|
364
|
+
### Slow inference
|
|
365
|
+
|
|
366
|
+
- Use `backend: 'webgpu'` if available
|
|
367
|
+
- Reduce `inputSize` to `[416, 416]`
|
|
368
|
+
- Increase `confidence` threshold
|
|
369
|
+
- Filter to specific `classes`
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
Apache 2.0
|