tempest-react-sdk 0.19.0 → 0.20.0
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/README.md +3 -3
- package/dist/styles.css +1 -1
- package/dist/tempest-react-sdk.cjs +3 -3
- package/dist/tempest-react-sdk.cjs.map +1 -1
- package/dist/tempest-react-sdk.d.ts +9 -0
- package/dist/tempest-react-sdk.js +1673 -1660
- package/dist/tempest-react-sdk.js.map +1 -1
- package/dist/vision.cjs +1 -1
- package/dist/vision.cjs.map +1 -1
- package/dist/vision.d.ts +142 -0
- package/dist/vision.js +499 -354
- package/dist/vision.js.map +1 -1
- package/package.json +1 -1
package/dist/vision.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { useState as K, useRef as tt, useEffect as _t } from "react";
|
|
2
|
+
import * as J from "onnxruntime-web";
|
|
3
|
+
class B extends Error {
|
|
3
4
|
constructor(t, e) {
|
|
4
5
|
super(t, e), this.name = new.target.name;
|
|
5
6
|
}
|
|
6
7
|
}
|
|
7
|
-
class
|
|
8
|
+
class zt extends B {
|
|
8
9
|
}
|
|
9
|
-
class
|
|
10
|
+
class ut extends B {
|
|
10
11
|
}
|
|
11
|
-
class
|
|
12
|
+
class ce extends B {
|
|
12
13
|
}
|
|
13
|
-
class
|
|
14
|
+
class E extends B {
|
|
14
15
|
}
|
|
15
|
-
class
|
|
16
|
+
class q extends B {
|
|
16
17
|
}
|
|
17
|
-
class
|
|
18
|
+
class D {
|
|
18
19
|
constructor(t, e, s) {
|
|
19
20
|
if (this.data = t, this.width = e, this.height = s, t.length !== e * s * 3)
|
|
20
|
-
throw new
|
|
21
|
+
throw new E(
|
|
21
22
|
`RGBImage data length ${t.length} does not match width * height * 3 = ${e * s * 3}.`
|
|
22
23
|
);
|
|
23
24
|
}
|
|
@@ -25,7 +26,7 @@ class L {
|
|
|
25
26
|
width;
|
|
26
27
|
height;
|
|
27
28
|
}
|
|
28
|
-
class
|
|
29
|
+
class vt {
|
|
29
30
|
constructor(t, e, s, n) {
|
|
30
31
|
this.x1 = t, this.y1 = e, this.x2 = s, this.y2 = n;
|
|
31
32
|
}
|
|
@@ -96,10 +97,10 @@ class gt {
|
|
|
96
97
|
return [Math.trunc(this.x1), Math.trunc(this.y1), Math.trunc(this.x2), Math.trunc(this.y2)];
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
class
|
|
100
|
+
class Y {
|
|
100
101
|
constructor(t, e, s) {
|
|
101
102
|
if (this.data = t, this.width = e, this.height = s, t.length !== e * s)
|
|
102
|
-
throw new
|
|
103
|
+
throw new E(
|
|
103
104
|
`Mask data length ${t.length} does not match width * height = ${e * s}.`
|
|
104
105
|
);
|
|
105
106
|
}
|
|
@@ -107,7 +108,7 @@ class B {
|
|
|
107
108
|
width;
|
|
108
109
|
height;
|
|
109
110
|
}
|
|
110
|
-
class
|
|
111
|
+
class Mt {
|
|
111
112
|
/**
|
|
112
113
|
* @param xyxy Flat array of length `4 * N` in `[x1, y1, x2, y2, ...]` order.
|
|
113
114
|
* @param cls One class index per box, length `N`.
|
|
@@ -166,7 +167,7 @@ class xt {
|
|
|
166
167
|
return t;
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
|
-
class
|
|
170
|
+
class Ut {
|
|
170
171
|
/** @param data `[numClasses]` per-class probabilities, indexed by class id. */
|
|
171
172
|
constructor(t) {
|
|
172
173
|
this.data = t;
|
|
@@ -212,7 +213,7 @@ class Nt {
|
|
|
212
213
|
return { indices: n, values: r };
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
|
-
class
|
|
216
|
+
class Rt {
|
|
216
217
|
/**
|
|
217
218
|
* @param data Per-instance binary masks (`Mask` objects from `types.ts`).
|
|
218
219
|
* @param xyxy Flat `[N, 4]` of bounding-box coordinates in original pixels.
|
|
@@ -236,7 +237,7 @@ class Ot {
|
|
|
236
237
|
return this.data[Symbol.iterator]();
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
class
|
|
240
|
+
class Yt {
|
|
240
241
|
constructor(t, e, s, n, r, a = null, i = {}) {
|
|
241
242
|
this.boxes = t, this.detections = e, this.names = s, this.origImg = n, this.origShape = r, this.path = a, this.speed = i;
|
|
242
243
|
}
|
|
@@ -259,7 +260,7 @@ class zt {
|
|
|
259
260
|
return this.detections[Symbol.iterator]();
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
|
-
class
|
|
263
|
+
class Bt {
|
|
263
264
|
constructor(t, e, s, n, r, a = null, i = {}) {
|
|
264
265
|
this.probs = t, this.result = e, this.names = s, this.origImg = n, this.origShape = r, this.path = a, this.speed = i;
|
|
265
266
|
}
|
|
@@ -287,7 +288,7 @@ class Lt {
|
|
|
287
288
|
return this.result.probabilities;
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
|
-
class
|
|
291
|
+
class Xt {
|
|
291
292
|
constructor(t, e, s, n, r, a, i = null, c = {}) {
|
|
292
293
|
this.boxes = t, this.masks = e, this.detections = s, this.names = n, this.origImg = r, this.origShape = a, this.path = i, this.speed = c;
|
|
293
294
|
}
|
|
@@ -311,7 +312,7 @@ class Dt {
|
|
|
311
312
|
return this.detections[Symbol.iterator]();
|
|
312
313
|
}
|
|
313
314
|
}
|
|
314
|
-
const
|
|
315
|
+
const Vt = Object.freeze([
|
|
315
316
|
"person",
|
|
316
317
|
"bicycle",
|
|
317
318
|
"car",
|
|
@@ -392,21 +393,21 @@ const Yt = Object.freeze([
|
|
|
392
393
|
"teddy bear",
|
|
393
394
|
"hair drier",
|
|
394
395
|
"toothbrush"
|
|
395
|
-
]),
|
|
396
|
-
coco:
|
|
396
|
+
]), ft = {
|
|
397
|
+
coco: Vt
|
|
397
398
|
};
|
|
398
|
-
function
|
|
399
|
-
const e =
|
|
399
|
+
function st(o, t = {}) {
|
|
400
|
+
const e = jt(o, t.numClasses);
|
|
400
401
|
if (t.numClasses !== void 0 && e.length !== t.numClasses)
|
|
401
|
-
throw new
|
|
402
|
+
throw new q(
|
|
402
403
|
`Resolved ${e.length} labels but the model has ${t.numClasses} classes.`
|
|
403
404
|
);
|
|
404
405
|
return e;
|
|
405
406
|
}
|
|
406
|
-
function
|
|
407
|
+
function jt(o, t) {
|
|
407
408
|
if (o == null) {
|
|
408
409
|
if (t === void 0)
|
|
409
|
-
throw new
|
|
410
|
+
throw new q(
|
|
410
411
|
"Cannot auto-generate labels without numClasses. Pass an explicit labels spec or numClasses."
|
|
411
412
|
);
|
|
412
413
|
return Array.from({ length: t }, (e, s) => `class_${s}`);
|
|
@@ -414,11 +415,11 @@ function Ut(o, t) {
|
|
|
414
415
|
if (Array.isArray(o))
|
|
415
416
|
return [...o];
|
|
416
417
|
if (typeof o == "string") {
|
|
417
|
-
const e =
|
|
418
|
+
const e = ft[o];
|
|
418
419
|
if (e !== void 0)
|
|
419
420
|
return e;
|
|
420
|
-
throw new
|
|
421
|
-
`Unknown labels preset: ${JSON.stringify(o)}. Known presets: ${Object.keys(
|
|
421
|
+
throw new q(
|
|
422
|
+
`Unknown labels preset: ${JSON.stringify(o)}. Known presets: ${Object.keys(ft).join(", ")}.`
|
|
422
423
|
);
|
|
423
424
|
}
|
|
424
425
|
if (typeof o == "object") {
|
|
@@ -428,11 +429,11 @@ function Ut(o, t) {
|
|
|
428
429
|
const n = Math.max(...s);
|
|
429
430
|
return Array.from({ length: n + 1 }, (r, a) => e[a] ?? `class_${a}`);
|
|
430
431
|
}
|
|
431
|
-
throw new
|
|
432
|
+
throw new q(`Unsupported labels spec type: ${typeof o}.`);
|
|
432
433
|
}
|
|
433
|
-
const
|
|
434
|
-
function
|
|
435
|
-
return o === void 0 ? [...
|
|
434
|
+
const mt = ["webgpu", "wasm"];
|
|
435
|
+
function Pt(o) {
|
|
436
|
+
return o === void 0 ? [...mt] : o.length === 0 ? [...mt] : [...o];
|
|
436
437
|
}
|
|
437
438
|
class X {
|
|
438
439
|
constructor(t, e) {
|
|
@@ -448,18 +449,18 @@ class X {
|
|
|
448
449
|
* @throws {@link ModelLoadError} if the model cannot be loaded.
|
|
449
450
|
*/
|
|
450
451
|
static async create(t, e = {}) {
|
|
451
|
-
const s =
|
|
452
|
+
const s = Pt(e.providers), n = {
|
|
452
453
|
...e.sessionOptions ?? {},
|
|
453
454
|
executionProviders: s
|
|
454
455
|
};
|
|
455
456
|
let r;
|
|
456
457
|
try {
|
|
457
|
-
typeof t == "string" ? r = await
|
|
458
|
+
typeof t == "string" ? r = await J.InferenceSession.create(t, n) : t instanceof Uint8Array ? r = await J.InferenceSession.create(t, n) : r = await J.InferenceSession.create(
|
|
458
459
|
t,
|
|
459
460
|
n
|
|
460
461
|
);
|
|
461
462
|
} catch (a) {
|
|
462
|
-
throw new
|
|
463
|
+
throw new zt(`Failed to load ONNX model: ${a.message}`, {
|
|
463
464
|
cause: a
|
|
464
465
|
});
|
|
465
466
|
}
|
|
@@ -473,7 +474,7 @@ class X {
|
|
|
473
474
|
get inputName() {
|
|
474
475
|
const t = this._session.inputNames[0];
|
|
475
476
|
if (t === void 0)
|
|
476
|
-
throw new
|
|
477
|
+
throw new ut("Model has no inputs.");
|
|
477
478
|
return t;
|
|
478
479
|
}
|
|
479
480
|
/** Names of the model's outputs, in declaration order. */
|
|
@@ -494,129 +495,129 @@ class X {
|
|
|
494
495
|
try {
|
|
495
496
|
return await this._session.run(t);
|
|
496
497
|
} catch (e) {
|
|
497
|
-
throw new
|
|
498
|
+
throw new ut(`Inference failed: ${e.message}`, { cause: e });
|
|
498
499
|
}
|
|
499
500
|
}
|
|
500
501
|
}
|
|
501
|
-
function
|
|
502
|
+
function et(o, t) {
|
|
502
503
|
if (typeof OffscreenCanvas < "u")
|
|
503
504
|
return new OffscreenCanvas(o, t);
|
|
504
505
|
if (typeof document < "u") {
|
|
505
506
|
const e = document.createElement("canvas");
|
|
506
507
|
return e.width = o, e.height = t, e;
|
|
507
508
|
}
|
|
508
|
-
throw new
|
|
509
|
+
throw new E("No canvas implementation available in this environment.");
|
|
509
510
|
}
|
|
510
|
-
function
|
|
511
|
+
function nt(o) {
|
|
511
512
|
const t = o.getContext("2d");
|
|
512
513
|
if (t === null)
|
|
513
|
-
throw new
|
|
514
|
+
throw new E("Failed to obtain 2D rendering context.");
|
|
514
515
|
return t;
|
|
515
516
|
}
|
|
516
|
-
function
|
|
517
|
+
function ot(o) {
|
|
517
518
|
const { data: t, width: e, height: s } = o;
|
|
518
519
|
if (t.length !== e * s * 4)
|
|
519
|
-
throw new
|
|
520
|
+
throw new E(
|
|
520
521
|
`Unexpected ImageData length ${t.length} for ${e}x${s} (expected ${e * s * 4}).`
|
|
521
522
|
);
|
|
522
523
|
const n = new Uint8Array(e * s * 3);
|
|
523
524
|
for (let r = 0, a = 0; r < t.length; r += 4, a += 3)
|
|
524
525
|
n[a] = t[r], n[a + 1] = t[r + 1], n[a + 2] = t[r + 2];
|
|
525
|
-
return new
|
|
526
|
+
return new D(n, e, s);
|
|
526
527
|
}
|
|
527
|
-
function
|
|
528
|
+
function Ht(o) {
|
|
528
529
|
const t = new Uint8ClampedArray(o.width * o.height * 4);
|
|
529
530
|
for (let e = 0, s = 0; e < o.data.length; e += 3, s += 4)
|
|
530
531
|
t[s] = o.data[e], t[s + 1] = o.data[e + 1], t[s + 2] = o.data[e + 2], t[s + 3] = 255;
|
|
531
532
|
return new ImageData(t, o.width, o.height);
|
|
532
533
|
}
|
|
533
|
-
async function
|
|
534
|
-
if (o instanceof
|
|
534
|
+
async function rt(o) {
|
|
535
|
+
if (o instanceof D)
|
|
535
536
|
return o;
|
|
536
537
|
if (typeof ImageData < "u" && o instanceof ImageData)
|
|
537
|
-
return
|
|
538
|
+
return ot(o);
|
|
538
539
|
if (typeof o == "string")
|
|
539
|
-
return
|
|
540
|
+
return Gt(o);
|
|
540
541
|
if (typeof Blob < "u" && o instanceof Blob)
|
|
541
|
-
return
|
|
542
|
+
return At(o);
|
|
542
543
|
if (typeof HTMLImageElement < "u" && o instanceof HTMLImageElement)
|
|
543
|
-
return await
|
|
544
|
+
return await Kt(o), R(o, o.naturalWidth, o.naturalHeight);
|
|
544
545
|
if (typeof HTMLCanvasElement < "u" && o instanceof HTMLCanvasElement || typeof OffscreenCanvas < "u" && o instanceof OffscreenCanvas || typeof ImageBitmap < "u" && o instanceof ImageBitmap)
|
|
545
|
-
return
|
|
546
|
-
throw new
|
|
546
|
+
return R(o, o.width, o.height);
|
|
547
|
+
throw new E(
|
|
547
548
|
`Unsupported image source type: ${Object.prototype.toString.call(o)}`
|
|
548
549
|
);
|
|
549
550
|
}
|
|
550
|
-
async function
|
|
551
|
+
async function Gt(o) {
|
|
551
552
|
let t;
|
|
552
553
|
try {
|
|
553
554
|
t = await fetch(o);
|
|
554
555
|
} catch (s) {
|
|
555
|
-
throw new
|
|
556
|
+
throw new E(`Failed to fetch image from ${o}: ${s.message}`, {
|
|
556
557
|
cause: s
|
|
557
558
|
});
|
|
558
559
|
}
|
|
559
560
|
if (!t.ok)
|
|
560
|
-
throw new
|
|
561
|
+
throw new E(
|
|
561
562
|
`Failed to fetch image from ${o}: HTTP ${t.status} ${t.statusText}`
|
|
562
563
|
);
|
|
563
564
|
const e = await t.blob();
|
|
564
|
-
return
|
|
565
|
+
return At(e);
|
|
565
566
|
}
|
|
566
|
-
async function
|
|
567
|
+
async function At(o) {
|
|
567
568
|
let t;
|
|
568
569
|
try {
|
|
569
570
|
t = await createImageBitmap(o);
|
|
570
571
|
} catch (e) {
|
|
571
|
-
throw new
|
|
572
|
+
throw new E(`Failed to decode image blob: ${e.message}`, {
|
|
572
573
|
cause: e
|
|
573
574
|
});
|
|
574
575
|
}
|
|
575
576
|
try {
|
|
576
|
-
return
|
|
577
|
+
return R(t, t.width, t.height);
|
|
577
578
|
} finally {
|
|
578
579
|
t.close();
|
|
579
580
|
}
|
|
580
581
|
}
|
|
581
|
-
function
|
|
582
|
+
function Kt(o) {
|
|
582
583
|
return o.complete && o.naturalWidth > 0 ? Promise.resolve() : new Promise((t, e) => {
|
|
583
584
|
const s = () => {
|
|
584
585
|
r(), t();
|
|
585
586
|
}, n = () => {
|
|
586
|
-
r(), e(new
|
|
587
|
+
r(), e(new E("Failed to load HTMLImageElement (load event errored)"));
|
|
587
588
|
}, r = () => {
|
|
588
589
|
o.removeEventListener("load", s), o.removeEventListener("error", n);
|
|
589
590
|
};
|
|
590
591
|
o.addEventListener("load", s, { once: !0 }), o.addEventListener("error", n, { once: !0 });
|
|
591
592
|
});
|
|
592
593
|
}
|
|
593
|
-
function
|
|
594
|
+
function R(o, t, e) {
|
|
594
595
|
if (t === 0 || e === 0)
|
|
595
|
-
throw new
|
|
596
|
-
const s =
|
|
596
|
+
throw new E(`Cannot load image with zero dimension (${t}x${e}).`);
|
|
597
|
+
const s = et(t, e), n = nt(s);
|
|
597
598
|
n.drawImage(o, 0, 0);
|
|
598
599
|
const r = n.getImageData(0, 0, t, e);
|
|
599
|
-
return
|
|
600
|
+
return ot(r);
|
|
600
601
|
}
|
|
601
|
-
function
|
|
602
|
+
function It(o, t, e) {
|
|
602
603
|
if (t <= 0 || e <= 0)
|
|
603
604
|
throw new Error(`Invalid resize target ${t}x${e}.`);
|
|
604
605
|
if (t === o.width && e === o.height)
|
|
605
606
|
return o;
|
|
606
|
-
const s =
|
|
607
|
-
|
|
608
|
-
const r =
|
|
607
|
+
const s = et(o.width, o.height);
|
|
608
|
+
nt(s).putImageData(Ht(o), 0, 0);
|
|
609
|
+
const r = et(t, e), a = nt(r);
|
|
609
610
|
a.imageSmoothingEnabled = !0, a.imageSmoothingQuality = "high", a.drawImage(s, 0, 0, t, e);
|
|
610
611
|
const i = a.getImageData(0, 0, t, e);
|
|
611
|
-
return
|
|
612
|
+
return ot(i);
|
|
612
613
|
}
|
|
613
|
-
function
|
|
614
|
-
const n = new Float32Array(o.data.length), r = o.data, a = t[0], i = t[1], c = t[2],
|
|
614
|
+
function Jt(o, t, e, s = 1 / 255) {
|
|
615
|
+
const n = new Float32Array(o.data.length), r = o.data, a = t[0], i = t[1], c = t[2], h = e[0], u = e[1], d = e[2];
|
|
615
616
|
for (let l = 0; l < r.length; l += 3)
|
|
616
|
-
n[l] = (r[l] * s - a) /
|
|
617
|
+
n[l] = (r[l] * s - a) / h, n[l + 1] = (r[l + 1] * s - i) / u, n[l + 2] = (r[l + 2] * s - c) / d;
|
|
617
618
|
return n;
|
|
618
619
|
}
|
|
619
|
-
function
|
|
620
|
+
function at(o, t = 1 / 255) {
|
|
620
621
|
const e = new Float32Array(o.data.length), s = o.data;
|
|
621
622
|
for (let n = 0; n < s.length; n++)
|
|
622
623
|
e[n] = s[n] * t;
|
|
@@ -631,20 +632,20 @@ function Q(o, t, e, s = 3) {
|
|
|
631
632
|
const r = new Float32Array(n), a = t * e;
|
|
632
633
|
for (let i = 0; i < e; i++)
|
|
633
634
|
for (let c = 0; c < t; c++) {
|
|
634
|
-
const
|
|
635
|
-
for (let
|
|
636
|
-
r[
|
|
635
|
+
const h = (i * t + c) * s, u = i * t + c;
|
|
636
|
+
for (let d = 0; d < s; d++)
|
|
637
|
+
r[d * a + u] = o[h + d];
|
|
637
638
|
}
|
|
638
639
|
return r;
|
|
639
640
|
}
|
|
640
|
-
function
|
|
641
|
-
return new
|
|
641
|
+
function it(o, t) {
|
|
642
|
+
return new J.Tensor("float32", o, t);
|
|
642
643
|
}
|
|
643
|
-
function
|
|
644
|
-
const t =
|
|
644
|
+
function he(o) {
|
|
645
|
+
const t = at(o);
|
|
645
646
|
return Q(t, o.width, o.height, 3);
|
|
646
647
|
}
|
|
647
|
-
function
|
|
648
|
+
function le(o, t, e) {
|
|
648
649
|
if (o.length !== t * e * 3)
|
|
649
650
|
throw new Error(
|
|
650
651
|
`fromCv2: data length ${o.length} does not match width * height * 3 = ${t * e * 3}.`
|
|
@@ -652,31 +653,31 @@ function ee(o, t, e) {
|
|
|
652
653
|
const s = new Uint8Array(o.length);
|
|
653
654
|
for (let n = 0; n < o.length; n += 3)
|
|
654
655
|
s[n] = o[n + 2], s[n + 1] = o[n + 1], s[n + 2] = o[n];
|
|
655
|
-
return new
|
|
656
|
+
return new D(s, t, e);
|
|
656
657
|
}
|
|
657
|
-
function
|
|
658
|
+
function de(o) {
|
|
658
659
|
const t = o.data, e = new Uint8Array(t.length);
|
|
659
660
|
for (let s = 0; s < t.length; s += 3)
|
|
660
661
|
e[s] = t[s + 2], e[s + 1] = t[s + 1], e[s + 2] = t[s];
|
|
661
662
|
return e;
|
|
662
663
|
}
|
|
663
|
-
function
|
|
664
|
-
const n = Math.min(t / o.width, e / o.height), r = Math.round(o.width * n), a = Math.round(o.height * n), i =
|
|
665
|
-
for (let
|
|
666
|
-
c[
|
|
667
|
-
const l = Math.floor((t - r) / 2),
|
|
668
|
-
for (let
|
|
669
|
-
const
|
|
670
|
-
c.set(i.data.subarray(
|
|
664
|
+
function St(o, t, e, s = [114, 114, 114]) {
|
|
665
|
+
const n = Math.min(t / o.width, e / o.height), r = Math.round(o.width * n), a = Math.round(o.height * n), i = It(o, r, a), c = new Uint8Array(t * e * 3), h = s[0], u = s[1], d = s[2];
|
|
666
|
+
for (let f = 0; f < c.length; f += 3)
|
|
667
|
+
c[f] = h, c[f + 1] = u, c[f + 2] = d;
|
|
668
|
+
const l = Math.floor((t - r) / 2), y = Math.floor((e - a) / 2), g = r * 3;
|
|
669
|
+
for (let f = 0; f < a; f++) {
|
|
670
|
+
const m = f * g, x = ((y + f) * t + l) * 3;
|
|
671
|
+
c.set(i.data.subarray(m, m + g), x);
|
|
671
672
|
}
|
|
672
673
|
return {
|
|
673
|
-
image: new
|
|
674
|
+
image: new D(c, t, e),
|
|
674
675
|
scale: n,
|
|
675
676
|
padLeft: l,
|
|
676
|
-
padTop:
|
|
677
|
+
padTop: y
|
|
677
678
|
};
|
|
678
679
|
}
|
|
679
|
-
function
|
|
680
|
+
function qt(o) {
|
|
680
681
|
const t = o.length, e = new Float32Array(t);
|
|
681
682
|
let s = -1 / 0;
|
|
682
683
|
for (let r = 0; r < t; r++) {
|
|
@@ -692,7 +693,7 @@ function Pt(o) {
|
|
|
692
693
|
e[r] = e[r] / n;
|
|
693
694
|
return e;
|
|
694
695
|
}
|
|
695
|
-
function
|
|
696
|
+
function Qt(o, t) {
|
|
696
697
|
const e = o.length, s = t === null ? e : Math.min(Math.max(0, t), e), n = new Array(e);
|
|
697
698
|
for (let i = 0; i < e; i++) n[i] = i;
|
|
698
699
|
n.sort((i, c) => o[c] - o[i]);
|
|
@@ -703,33 +704,33 @@ function Kt(o, t) {
|
|
|
703
704
|
}
|
|
704
705
|
return { indices: r, values: a };
|
|
705
706
|
}
|
|
706
|
-
function
|
|
707
|
+
function Zt(o, t, e) {
|
|
707
708
|
const s = t.length;
|
|
708
709
|
if (s === 0) return new Int32Array(0);
|
|
709
710
|
const n = new Float32Array(s);
|
|
710
711
|
for (let c = 0; c < s; c++) {
|
|
711
|
-
const
|
|
712
|
-
n[c] = Math.max(0,
|
|
712
|
+
const h = o[c * 4], u = o[c * 4 + 1], d = o[c * 4 + 2], l = o[c * 4 + 3];
|
|
713
|
+
n[c] = Math.max(0, d - h) * Math.max(0, l - u);
|
|
713
714
|
}
|
|
714
715
|
const r = new Array(s);
|
|
715
716
|
for (let c = 0; c < s; c++) r[c] = c;
|
|
716
|
-
r.sort((c,
|
|
717
|
+
r.sort((c, h) => t[h] - t[c]);
|
|
717
718
|
const a = new Uint8Array(s), i = [];
|
|
718
719
|
for (let c = 0; c < r.length; c++) {
|
|
719
|
-
const
|
|
720
|
-
if (a[
|
|
721
|
-
i.push(
|
|
722
|
-
const
|
|
723
|
-
for (let
|
|
724
|
-
const
|
|
725
|
-
if (a[
|
|
726
|
-
const
|
|
727
|
-
(
|
|
720
|
+
const h = r[c];
|
|
721
|
+
if (a[h]) continue;
|
|
722
|
+
i.push(h);
|
|
723
|
+
const u = o[h * 4], d = o[h * 4 + 1], l = o[h * 4 + 2], y = o[h * 4 + 3], g = n[h];
|
|
724
|
+
for (let f = c + 1; f < r.length; f++) {
|
|
725
|
+
const m = r[f];
|
|
726
|
+
if (a[m]) continue;
|
|
727
|
+
const x = o[m * 4], _ = o[m * 4 + 1], p = o[m * 4 + 2], S = o[m * 4 + 3], A = Math.max(u, x), M = Math.max(d, _), v = Math.min(l, p), C = Math.min(y, S), k = Math.max(0, v - A), w = Math.max(0, C - M), b = k * w, I = g + n[m] - b;
|
|
728
|
+
(I > 0 ? b / I : 0) > e && (a[m] = 1);
|
|
728
729
|
}
|
|
729
730
|
}
|
|
730
731
|
return Int32Array.from(i);
|
|
731
732
|
}
|
|
732
|
-
function
|
|
733
|
+
function Wt(o, t, e, s) {
|
|
733
734
|
if (t.length === 0) return new Int32Array(0);
|
|
734
735
|
const n = /* @__PURE__ */ new Map();
|
|
735
736
|
for (let a = 0; a < e.length; a++) {
|
|
@@ -738,18 +739,18 @@ function Ht(o, t, e, s) {
|
|
|
738
739
|
}
|
|
739
740
|
const r = [];
|
|
740
741
|
for (const a of n.values()) {
|
|
741
|
-
const i = a.length, c = new Float32Array(i * 4),
|
|
742
|
-
for (let
|
|
743
|
-
const l = a[
|
|
744
|
-
c[
|
|
742
|
+
const i = a.length, c = new Float32Array(i * 4), h = new Float32Array(i);
|
|
743
|
+
for (let d = 0; d < i; d++) {
|
|
744
|
+
const l = a[d];
|
|
745
|
+
c[d * 4] = o[l * 4], c[d * 4 + 1] = o[l * 4 + 1], c[d * 4 + 2] = o[l * 4 + 2], c[d * 4 + 3] = o[l * 4 + 3], h[d] = t[l];
|
|
745
746
|
}
|
|
746
|
-
const
|
|
747
|
-
for (let
|
|
748
|
-
r.push(a[
|
|
747
|
+
const u = Zt(c, h, s);
|
|
748
|
+
for (let d = 0; d < u.length; d++)
|
|
749
|
+
r.push(a[u[d]]);
|
|
749
750
|
}
|
|
750
751
|
return r.sort((a, i) => t[i] - t[a]), Int32Array.from(r);
|
|
751
752
|
}
|
|
752
|
-
function
|
|
753
|
+
function ct(o, t, e) {
|
|
753
754
|
let s = t;
|
|
754
755
|
if (s.length === 3) {
|
|
755
756
|
if (s[0] !== 1)
|
|
@@ -764,12 +765,12 @@ function at(o, t, e) {
|
|
|
764
765
|
numClasses: a,
|
|
765
766
|
originalWidth: i,
|
|
766
767
|
originalHeight: c,
|
|
767
|
-
padLeft:
|
|
768
|
-
padTop:
|
|
769
|
-
scale:
|
|
768
|
+
padLeft: h,
|
|
769
|
+
padTop: u,
|
|
770
|
+
scale: d,
|
|
770
771
|
confThreshold: l,
|
|
771
|
-
iouThreshold:
|
|
772
|
-
maxDetections:
|
|
772
|
+
iouThreshold: y,
|
|
773
|
+
maxDetections: g
|
|
773
774
|
} = e;
|
|
774
775
|
if (a < 1 || a + 4 > n)
|
|
775
776
|
throw new Error(
|
|
@@ -779,34 +780,34 @@ function at(o, t, e) {
|
|
|
779
780
|
throw new Error(
|
|
780
781
|
`decodeYoloAnchors: data length ${o.length} does not match channels*numAnchors=${n * r}.`
|
|
781
782
|
);
|
|
782
|
-
const
|
|
783
|
-
for (let
|
|
784
|
-
let b = 0,
|
|
785
|
-
for (let
|
|
786
|
-
const
|
|
787
|
-
|
|
783
|
+
const f = [];
|
|
784
|
+
for (let w = 0; w < r; w++) {
|
|
785
|
+
let b = 0, I = -1 / 0;
|
|
786
|
+
for (let U = 0; U < a; U++) {
|
|
787
|
+
const O = o[(4 + U) * r + w];
|
|
788
|
+
O !== void 0 && O > I && (I = O, b = U);
|
|
788
789
|
}
|
|
789
|
-
if (
|
|
790
|
-
const T = o[
|
|
791
|
-
let
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
if (
|
|
795
|
-
const
|
|
796
|
-
for (let
|
|
797
|
-
const b =
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
const
|
|
801
|
-
if (
|
|
802
|
-
const S = Array.from(
|
|
803
|
-
for (let
|
|
804
|
-
const b =
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
return { anchorIndices:
|
|
790
|
+
if (I < l) continue;
|
|
791
|
+
const T = o[w], V = o[r + w], j = o[2 * r + w], P = o[3 * r + w];
|
|
792
|
+
let z = T - j / 2, $ = V - P / 2, F = T + j / 2, L = V + P / 2;
|
|
793
|
+
z = (z - h) / d, $ = ($ - u) / d, F = (F - h) / d, L = (L - u) / d, z = Math.max(0, Math.min(i, z)), $ = Math.max(0, Math.min(c, $)), F = Math.max(0, Math.min(i, F)), L = Math.max(0, Math.min(c, L)), f.push({ anchorIdx: w, x1: z, y1: $, x2: F, y2: L, classId: b, confidence: I });
|
|
794
|
+
}
|
|
795
|
+
if (f.length === 0) return wt();
|
|
796
|
+
const m = new Float32Array(f.length * 4), x = new Float32Array(f.length), _ = new Int32Array(f.length);
|
|
797
|
+
for (let w = 0; w < f.length; w++) {
|
|
798
|
+
const b = f[w];
|
|
799
|
+
m[w * 4] = b.x1, m[w * 4 + 1] = b.y1, m[w * 4 + 2] = b.x2, m[w * 4 + 3] = b.y2, x[w] = b.confidence, _[w] = b.classId;
|
|
800
|
+
}
|
|
801
|
+
const p = Wt(m, x, _, y);
|
|
802
|
+
if (p.length === 0) return wt();
|
|
803
|
+
const S = Array.from(p).slice(0, g), A = S.length, M = new Int32Array(A), v = new Float32Array(A * 4), C = new Int32Array(A), k = new Float32Array(A);
|
|
804
|
+
for (let w = 0; w < A; w++) {
|
|
805
|
+
const b = f[S[w]];
|
|
806
|
+
M[w] = b.anchorIdx, v[w * 4] = b.x1, v[w * 4 + 1] = b.y1, v[w * 4 + 2] = b.x2, v[w * 4 + 3] = b.y2, C[w] = b.classId, k[w] = b.confidence;
|
|
807
|
+
}
|
|
808
|
+
return { anchorIndices: M, boxesXyxy: v, classIds: C, confidences: k };
|
|
808
809
|
}
|
|
809
|
-
function
|
|
810
|
+
function wt() {
|
|
810
811
|
return {
|
|
811
812
|
anchorIndices: new Int32Array(0),
|
|
812
813
|
boxesXyxy: new Float32Array(0),
|
|
@@ -814,17 +815,17 @@ function ft() {
|
|
|
814
815
|
confidences: new Float32Array(0)
|
|
815
816
|
};
|
|
816
817
|
}
|
|
817
|
-
function
|
|
818
|
+
function Tt(o, t, e) {
|
|
818
819
|
const s = t.length === 3 ? t[1] : t[0];
|
|
819
820
|
if (s === void 0 || s < 5)
|
|
820
821
|
throw new Error(`decodeYolo: invalid output channel count ${s} (expected >= 5).`);
|
|
821
|
-
const n = s - 4, r =
|
|
822
|
+
const n = s - 4, r = ct(o, t, {
|
|
822
823
|
numClasses: n,
|
|
823
824
|
...e
|
|
824
825
|
}), a = [];
|
|
825
826
|
for (let i = 0; i < r.classIds.length; i++)
|
|
826
827
|
a.push({
|
|
827
|
-
bbox: new
|
|
828
|
+
bbox: new vt(
|
|
828
829
|
r.boxesXyxy[i * 4],
|
|
829
830
|
r.boxesXyxy[i * 4 + 1],
|
|
830
831
|
r.boxesXyxy[i * 4 + 2],
|
|
@@ -835,18 +836,18 @@ function Mt(o, t, e) {
|
|
|
835
836
|
});
|
|
836
837
|
return a;
|
|
837
838
|
}
|
|
838
|
-
let yt = !1,
|
|
839
|
-
function
|
|
839
|
+
let yt = !1, gt = !1;
|
|
840
|
+
function ue(o, t, e) {
|
|
840
841
|
return yt || (yt = !0, console.warn(
|
|
841
842
|
"[@ort-vision-sdk/web] decodeYoloV8 is deprecated since 0.2.0; use decodeYolo. The alias will be removed in 0.3.0."
|
|
842
|
-
)),
|
|
843
|
+
)), Tt(o, t, e);
|
|
843
844
|
}
|
|
844
|
-
function
|
|
845
|
-
return
|
|
845
|
+
function fe(o, t, e) {
|
|
846
|
+
return gt || (gt = !0, console.warn(
|
|
846
847
|
"[@ort-vision-sdk/web] decodeYoloV8Anchors is deprecated since 0.2.0; use decodeYoloAnchors. The alias will be removed in 0.3.0."
|
|
847
|
-
)),
|
|
848
|
+
)), ct(o, t, e);
|
|
848
849
|
}
|
|
849
|
-
function
|
|
850
|
+
function Et(o, t, e, s, n) {
|
|
850
851
|
let r = s;
|
|
851
852
|
if (r.length === 4) {
|
|
852
853
|
if (r[0] !== 1)
|
|
@@ -857,21 +858,21 @@ function vt(o, t, e, s, n) {
|
|
|
857
858
|
throw new Error(
|
|
858
859
|
`decodeYoloSeg: expected 3-D prototypes after batch removal, got dims=${JSON.stringify(s)}.`
|
|
859
860
|
);
|
|
860
|
-
const a = r[0], i = r[1], c = r[2],
|
|
861
|
-
if (
|
|
861
|
+
const a = r[0], i = r[1], c = r[2], h = t.length === 3 ? t[1] : t[0], u = t.length === 3 ? t[2] : t[1];
|
|
862
|
+
if (h === void 0 || u === void 0)
|
|
862
863
|
throw new Error(
|
|
863
864
|
`decodeYoloSeg: cannot read channels/numAnchors from dims=${JSON.stringify(t)}.`
|
|
864
865
|
);
|
|
865
|
-
const
|
|
866
|
-
if (
|
|
866
|
+
const d = 4 + n.numClasses + a;
|
|
867
|
+
if (h !== d)
|
|
867
868
|
throw new Error(
|
|
868
|
-
`decodeYoloSeg: channels=${
|
|
869
|
+
`decodeYoloSeg: channels=${h} does not match 4 + numClasses(${n.numClasses}) + numMaskCoefs(${a}) = ${d}.`
|
|
869
870
|
);
|
|
870
871
|
if (e.length !== a * i * c)
|
|
871
872
|
throw new Error(
|
|
872
873
|
`decodeYoloSeg: prototype length ${e.length} does not match dims=${JSON.stringify(s)}.`
|
|
873
874
|
);
|
|
874
|
-
const l =
|
|
875
|
+
const l = ct(o, t, {
|
|
875
876
|
numClasses: n.numClasses,
|
|
876
877
|
originalWidth: n.originalWidth,
|
|
877
878
|
originalHeight: n.originalHeight,
|
|
@@ -883,56 +884,56 @@ function vt(o, t, e, s, n) {
|
|
|
883
884
|
maxDetections: n.maxDetections
|
|
884
885
|
});
|
|
885
886
|
if (l.anchorIndices.length === 0) return [];
|
|
886
|
-
const
|
|
887
|
-
for (let
|
|
888
|
-
const S = l.anchorIndices[
|
|
889
|
-
if (
|
|
890
|
-
_.push({ bbox:
|
|
887
|
+
const y = n.maskThreshold ?? 0.5, g = c / n.inputWidth, f = i / n.inputHeight, m = i * c, x = (4 + n.numClasses) * u, _ = [];
|
|
888
|
+
for (let p = 0; p < l.anchorIndices.length; p++) {
|
|
889
|
+
const S = l.anchorIndices[p], A = l.boxesXyxy[p * 4], M = l.boxesXyxy[p * 4 + 1], v = l.boxesXyxy[p * 4 + 2], C = l.boxesXyxy[p * 4 + 3], k = new vt(A, M, v, C), w = l.classIds[p], b = l.confidences[p], I = Math.max(0, Math.trunc(v) - Math.trunc(A)), T = Math.max(0, Math.trunc(C) - Math.trunc(M));
|
|
890
|
+
if (I === 0 || T === 0) {
|
|
891
|
+
_.push({ bbox: k, classId: w, confidence: b, mask: new Y(new Uint8Array(0), 0, 0) });
|
|
891
892
|
continue;
|
|
892
893
|
}
|
|
893
|
-
const V =
|
|
894
|
-
if (
|
|
894
|
+
const V = A * n.scale + n.padLeft, j = M * n.scale + n.padTop, P = v * n.scale + n.padLeft, z = C * n.scale + n.padTop, $ = Math.max(0, Math.floor(V * g)), F = Math.max(0, Math.floor(j * f)), L = Math.min(c, Math.ceil(P * g)), U = Math.min(i, Math.ceil(z * f));
|
|
895
|
+
if (L <= $ || U <= F) {
|
|
895
896
|
_.push({
|
|
896
|
-
bbox:
|
|
897
|
-
classId:
|
|
897
|
+
bbox: k,
|
|
898
|
+
classId: w,
|
|
898
899
|
confidence: b,
|
|
899
|
-
mask: new
|
|
900
|
+
mask: new Y(new Uint8Array(I * T), I, T)
|
|
900
901
|
});
|
|
901
902
|
continue;
|
|
902
903
|
}
|
|
903
|
-
const
|
|
904
|
+
const O = L - $, Z = U - F, lt = new Float32Array(O * Z);
|
|
904
905
|
for (let N = 0; N < Z; N++) {
|
|
905
|
-
const
|
|
906
|
-
for (let
|
|
907
|
-
const
|
|
908
|
-
let
|
|
906
|
+
const Nt = F + N;
|
|
907
|
+
for (let H = 0; H < O; H++) {
|
|
908
|
+
const Lt = $ + H;
|
|
909
|
+
let dt = 0;
|
|
909
910
|
for (let G = 0; G < a; G++) {
|
|
910
|
-
const
|
|
911
|
-
|
|
911
|
+
const Ot = o[x + G * u + S], Dt = e[G * m + Nt * c + Lt];
|
|
912
|
+
dt += Ot * Dt;
|
|
912
913
|
}
|
|
913
|
-
|
|
914
|
+
lt[N * O + H] = te(dt);
|
|
914
915
|
}
|
|
915
916
|
}
|
|
916
|
-
const
|
|
917
|
-
for (let N = 0; N <
|
|
918
|
-
|
|
919
|
-
_.push({ bbox:
|
|
917
|
+
const Ft = ee(lt, O, Z, I, T), W = new Uint8Array(I * T);
|
|
918
|
+
for (let N = 0; N < W.length; N++)
|
|
919
|
+
W[N] = Ft[N] >= y ? 255 : 0;
|
|
920
|
+
_.push({ bbox: k, classId: w, confidence: b, mask: new Y(W, I, T) });
|
|
920
921
|
}
|
|
921
922
|
return _;
|
|
922
923
|
}
|
|
923
|
-
function
|
|
924
|
+
function te(o) {
|
|
924
925
|
if (o >= 0)
|
|
925
926
|
return 1 / (1 + Math.exp(-o));
|
|
926
927
|
const t = Math.exp(o);
|
|
927
928
|
return t / (1 + t);
|
|
928
929
|
}
|
|
929
|
-
let
|
|
930
|
-
function
|
|
931
|
-
return
|
|
930
|
+
let pt = !1;
|
|
931
|
+
function me(o, t, e, s, n) {
|
|
932
|
+
return pt || (pt = !0, console.warn(
|
|
932
933
|
"[@ort-vision-sdk/web] decodeYoloV8Seg is deprecated since 0.2.0; use decodeYoloSeg. The alias will be removed in 0.3.0."
|
|
933
|
-
)),
|
|
934
|
+
)), Et(o, t, e, s, n);
|
|
934
935
|
}
|
|
935
|
-
function
|
|
936
|
+
function ee(o, t, e, s, n) {
|
|
936
937
|
const r = new Float32Array(s * n);
|
|
937
938
|
if (s === 0 || n === 0 || t === 0 || e === 0)
|
|
938
939
|
return r;
|
|
@@ -940,15 +941,15 @@ function Qt(o, t, e, s, n) {
|
|
|
940
941
|
return r.set(o), r;
|
|
941
942
|
const a = t / s, i = e / n;
|
|
942
943
|
for (let c = 0; c < n; c++) {
|
|
943
|
-
const
|
|
944
|
-
for (let
|
|
945
|
-
const
|
|
946
|
-
r[c * s +
|
|
944
|
+
const h = (c + 0.5) * i - 0.5, u = Math.max(0, Math.floor(h)), d = Math.min(e - 1, u + 1), l = Math.max(0, Math.min(1, h - u));
|
|
945
|
+
for (let y = 0; y < s; y++) {
|
|
946
|
+
const g = (y + 0.5) * a - 0.5, f = Math.max(0, Math.floor(g)), m = Math.min(t - 1, f + 1), x = Math.max(0, Math.min(1, g - f)), _ = o[u * t + f], p = o[u * t + m], S = o[d * t + f], A = o[d * t + m], M = _ * (1 - x) + p * x, v = S * (1 - x) + A * x;
|
|
947
|
+
r[c * s + y] = M * (1 - l) + v * l;
|
|
947
948
|
}
|
|
948
949
|
}
|
|
949
950
|
return r;
|
|
950
951
|
}
|
|
951
|
-
class
|
|
952
|
+
class ht {
|
|
952
953
|
constructor(t) {
|
|
953
954
|
this._session = t;
|
|
954
955
|
}
|
|
@@ -958,8 +959,8 @@ class it {
|
|
|
958
959
|
return this._session;
|
|
959
960
|
}
|
|
960
961
|
}
|
|
961
|
-
const
|
|
962
|
-
class
|
|
962
|
+
const ne = [0.485, 0.456, 0.406], se = [0.229, 0.224, 0.225];
|
|
963
|
+
class Ct extends ht {
|
|
963
964
|
constructor(t, e, s, n, r, a, i) {
|
|
964
965
|
super(t), this._labels = e, this._names = s, this._inputSize = n, this._mean = r, this._std = a, this._applySoftmax = i;
|
|
965
966
|
}
|
|
@@ -971,16 +972,16 @@ class It extends it {
|
|
|
971
972
|
_applySoftmax;
|
|
972
973
|
/** Load the model and resolve labels. */
|
|
973
974
|
static async create(t, e) {
|
|
974
|
-
const s = await X.create(t, e), n =
|
|
975
|
+
const s = await X.create(t, e), n = st(e.labels, { numClasses: e.numClasses }), r = {};
|
|
975
976
|
for (let a = 0; a < n.length; a++)
|
|
976
977
|
r[a] = n[a];
|
|
977
|
-
return new
|
|
978
|
+
return new Ct(
|
|
978
979
|
s,
|
|
979
980
|
n,
|
|
980
981
|
r,
|
|
981
982
|
e.inputSize ?? [224, 224],
|
|
982
|
-
e.mean ??
|
|
983
|
-
e.std ??
|
|
983
|
+
e.mean ?? ne,
|
|
984
|
+
e.std ?? se,
|
|
984
985
|
e.applySoftmax ?? !0
|
|
985
986
|
);
|
|
986
987
|
}
|
|
@@ -1002,7 +1003,7 @@ class It extends it {
|
|
|
1002
1003
|
}
|
|
1003
1004
|
/** Run classification on a single image. */
|
|
1004
1005
|
async predict(t, e = {}) {
|
|
1005
|
-
const s = typeof t == "string" ? t : null, n = await
|
|
1006
|
+
const s = typeof t == "string" ? t : null, n = await rt(t), r = this._preprocess(n), a = await this._session.run({ [this._session.inputName]: r }), i = this._session.outputNames[0];
|
|
1006
1007
|
if (i === void 0)
|
|
1007
1008
|
throw new Error("Classifier model has no outputs.");
|
|
1008
1009
|
const c = a[i];
|
|
@@ -1010,50 +1011,50 @@ class It extends it {
|
|
|
1010
1011
|
throw new Error(
|
|
1011
1012
|
`Classifier model output ${i} missing from run() result.`
|
|
1012
1013
|
);
|
|
1013
|
-
const
|
|
1014
|
-
for (let
|
|
1015
|
-
const
|
|
1014
|
+
const h = this._postprocess(c.data), { indices: u, values: d } = Qt(h, e.topK ?? null), l = [];
|
|
1015
|
+
for (let m = 0; m < u.length; m++) {
|
|
1016
|
+
const x = u[m], _ = this._labels[x] ?? `class_${x}`;
|
|
1016
1017
|
l.push({
|
|
1017
|
-
classId:
|
|
1018
|
+
classId: x,
|
|
1018
1019
|
className: _,
|
|
1019
|
-
probability:
|
|
1020
|
-
cls:
|
|
1020
|
+
probability: d[m],
|
|
1021
|
+
cls: x,
|
|
1021
1022
|
name: _,
|
|
1022
|
-
conf:
|
|
1023
|
+
conf: d[m]
|
|
1023
1024
|
});
|
|
1024
1025
|
}
|
|
1025
1026
|
if (l.length === 0)
|
|
1026
1027
|
throw new Error("Classifier produced no probabilities (empty output).");
|
|
1027
|
-
const
|
|
1028
|
-
classId:
|
|
1029
|
-
className:
|
|
1030
|
-
confidence:
|
|
1031
|
-
cls:
|
|
1032
|
-
name:
|
|
1033
|
-
conf:
|
|
1028
|
+
const y = l[0], g = {
|
|
1029
|
+
classId: y.classId,
|
|
1030
|
+
className: y.className,
|
|
1031
|
+
confidence: y.probability,
|
|
1032
|
+
cls: y.classId,
|
|
1033
|
+
name: y.className,
|
|
1034
|
+
conf: y.probability,
|
|
1034
1035
|
image: n,
|
|
1035
1036
|
probabilities: l
|
|
1036
|
-
},
|
|
1037
|
+
}, f = [n.height, n.width];
|
|
1037
1038
|
return [
|
|
1038
|
-
new
|
|
1039
|
-
new
|
|
1040
|
-
|
|
1039
|
+
new Bt(
|
|
1040
|
+
new Ut(h),
|
|
1041
|
+
g,
|
|
1041
1042
|
this._names,
|
|
1042
1043
|
n,
|
|
1043
|
-
|
|
1044
|
+
f,
|
|
1044
1045
|
s
|
|
1045
1046
|
)
|
|
1046
1047
|
];
|
|
1047
1048
|
}
|
|
1048
1049
|
_preprocess(t) {
|
|
1049
|
-
const [e, s] = this._inputSize, n =
|
|
1050
|
-
return
|
|
1050
|
+
const [e, s] = this._inputSize, n = It(t, e, s), r = Jt(n, this._mean, this._std), a = Q(r, n.width, n.height, 3);
|
|
1051
|
+
return it(a, [1, 3, n.height, n.width]);
|
|
1051
1052
|
}
|
|
1052
1053
|
_postprocess(t) {
|
|
1053
|
-
return this._applySoftmax ?
|
|
1054
|
+
return this._applySoftmax ? qt(t) : new Float32Array(t);
|
|
1054
1055
|
}
|
|
1055
1056
|
}
|
|
1056
|
-
class
|
|
1057
|
+
class kt extends ht {
|
|
1057
1058
|
constructor(t, e, s, n, r, a, i, c) {
|
|
1058
1059
|
super(t), this._head = e, this._labels = s, this._names = n, this._inputSize = r, this._confThreshold = a, this._iouThreshold = i, this._maxDetections = c;
|
|
1059
1060
|
}
|
|
@@ -1069,12 +1070,12 @@ class At extends it {
|
|
|
1069
1070
|
const s = e.head ?? "yolo";
|
|
1070
1071
|
if (s !== "yolo")
|
|
1071
1072
|
throw new Error(`Unsupported detector head '${s}'. Supported: 'yolo'.`);
|
|
1072
|
-
const n = await X.create(t, e), r =
|
|
1073
|
+
const n = await X.create(t, e), r = st(e.labels ?? "coco", {
|
|
1073
1074
|
numClasses: e.numClasses
|
|
1074
1075
|
}), a = {};
|
|
1075
1076
|
for (let i = 0; i < r.length; i++)
|
|
1076
1077
|
a[i] = r[i];
|
|
1077
|
-
return new
|
|
1078
|
+
return new kt(
|
|
1078
1079
|
n,
|
|
1079
1080
|
s,
|
|
1080
1081
|
r,
|
|
@@ -1113,13 +1114,13 @@ class At extends it {
|
|
|
1113
1114
|
}
|
|
1114
1115
|
/** Run detection on a single image. */
|
|
1115
1116
|
async predict(t, e = {}) {
|
|
1116
|
-
const s = typeof t == "string" ? t : null, n = await
|
|
1117
|
-
if (
|
|
1117
|
+
const s = typeof t == "string" ? t : null, n = await rt(t), { tensor: r, scale: a, padLeft: i, padTop: c } = this._preprocess(n), h = await this._session.run({ [this._session.inputName]: r }), u = this._session.outputNames[0];
|
|
1118
|
+
if (u === void 0)
|
|
1118
1119
|
throw new Error("Detector model has no outputs.");
|
|
1119
|
-
const
|
|
1120
|
-
if (
|
|
1121
|
-
throw new Error(`Detector model output ${
|
|
1122
|
-
const l =
|
|
1120
|
+
const d = h[u];
|
|
1121
|
+
if (d === void 0)
|
|
1122
|
+
throw new Error(`Detector model output ${u} missing from run() result.`);
|
|
1123
|
+
const l = Tt(d.data, d.dims, {
|
|
1123
1124
|
originalWidth: n.width,
|
|
1124
1125
|
originalHeight: n.height,
|
|
1125
1126
|
padLeft: i,
|
|
@@ -1128,55 +1129,55 @@ class At extends it {
|
|
|
1128
1129
|
confThreshold: e.confThreshold ?? this._confThreshold,
|
|
1129
1130
|
iouThreshold: e.iouThreshold ?? this._iouThreshold,
|
|
1130
1131
|
maxDetections: this._maxDetections
|
|
1131
|
-
}),
|
|
1132
|
-
const
|
|
1133
|
-
return l.filter((
|
|
1132
|
+
}), g = (e.classes !== void 0 ? (() => {
|
|
1133
|
+
const m = new Set(e.classes);
|
|
1134
|
+
return l.filter((x) => m.has(x.classId));
|
|
1134
1135
|
})() : l).map(
|
|
1135
|
-
(
|
|
1136
|
-
),
|
|
1136
|
+
(m) => this._buildResult(n, m.bbox, m.classId, m.confidence)
|
|
1137
|
+
), f = [n.height, n.width];
|
|
1137
1138
|
return [
|
|
1138
|
-
new
|
|
1139
|
-
this._buildBoxes(
|
|
1140
|
-
|
|
1139
|
+
new Yt(
|
|
1140
|
+
this._buildBoxes(g, f),
|
|
1141
|
+
g,
|
|
1141
1142
|
this._names,
|
|
1142
1143
|
n,
|
|
1143
|
-
|
|
1144
|
+
f,
|
|
1144
1145
|
s
|
|
1145
1146
|
)
|
|
1146
1147
|
];
|
|
1147
1148
|
}
|
|
1148
1149
|
_preprocess(t) {
|
|
1149
|
-
const [e, s] = this._inputSize, n =
|
|
1150
|
+
const [e, s] = this._inputSize, n = St(t, e, s), r = at(n.image), a = Q(r, n.image.width, n.image.height, 3);
|
|
1150
1151
|
return {
|
|
1151
|
-
tensor:
|
|
1152
|
+
tensor: it(a, [1, 3, n.image.height, n.image.width]),
|
|
1152
1153
|
scale: n.scale,
|
|
1153
1154
|
padLeft: n.padLeft,
|
|
1154
1155
|
padTop: n.padTop
|
|
1155
1156
|
};
|
|
1156
1157
|
}
|
|
1157
1158
|
_buildResult(t, e, s, n) {
|
|
1158
|
-
const [r, a, i, c] = e.asIntXyxy(),
|
|
1159
|
-
let
|
|
1160
|
-
if (
|
|
1161
|
-
const
|
|
1162
|
-
for (let _ = 0; _ <
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1159
|
+
const [r, a, i, c] = e.asIntXyxy(), h = Math.max(0, r), u = Math.max(0, a), d = Math.min(t.width, i), l = Math.min(t.height, c);
|
|
1160
|
+
let y;
|
|
1161
|
+
if (d > h && l > u) {
|
|
1162
|
+
const f = d - h, m = l - u, x = new Uint8Array(f * m * 3);
|
|
1163
|
+
for (let _ = 0; _ < m; _++) {
|
|
1164
|
+
const p = ((u + _) * t.width + h) * 3;
|
|
1165
|
+
x.set(t.data.subarray(p, p + f * 3), _ * f * 3);
|
|
1165
1166
|
}
|
|
1166
|
-
|
|
1167
|
+
y = new D(x, f, m);
|
|
1167
1168
|
} else
|
|
1168
|
-
|
|
1169
|
-
const
|
|
1169
|
+
y = new D(new Uint8Array(0), 0, 0);
|
|
1170
|
+
const g = this._names[s] ?? `class_${s}`;
|
|
1170
1171
|
return {
|
|
1171
1172
|
classId: s,
|
|
1172
|
-
className:
|
|
1173
|
+
className: g,
|
|
1173
1174
|
confidence: n,
|
|
1174
1175
|
bbox: e,
|
|
1175
1176
|
cls: s,
|
|
1176
|
-
name:
|
|
1177
|
+
name: g,
|
|
1177
1178
|
conf: n,
|
|
1178
1179
|
box: e,
|
|
1179
|
-
croppedImage:
|
|
1180
|
+
croppedImage: y
|
|
1180
1181
|
};
|
|
1181
1182
|
}
|
|
1182
1183
|
_buildBoxes(t, e) {
|
|
@@ -1185,12 +1186,12 @@ class At extends it {
|
|
|
1185
1186
|
const c = t[i];
|
|
1186
1187
|
n[i * 4] = c.bbox.x1, n[i * 4 + 1] = c.bbox.y1, n[i * 4 + 2] = c.bbox.x2, n[i * 4 + 3] = c.bbox.y2, r[i] = c.classId, a[i] = c.confidence;
|
|
1187
1188
|
}
|
|
1188
|
-
return new
|
|
1189
|
+
return new Mt(n, r, a, e);
|
|
1189
1190
|
}
|
|
1190
1191
|
}
|
|
1191
|
-
class
|
|
1192
|
-
constructor(t, e, s, n, r, a, i, c,
|
|
1193
|
-
super(t), this._head = e, this._labels = s, this._names = n, this._inputSize = r, this._confThreshold = a, this._iouThreshold = i, this._maxDetections = c, this._maskThreshold =
|
|
1192
|
+
class $t extends ht {
|
|
1193
|
+
constructor(t, e, s, n, r, a, i, c, h) {
|
|
1194
|
+
super(t), this._head = e, this._labels = s, this._names = n, this._inputSize = r, this._confThreshold = a, this._iouThreshold = i, this._maxDetections = c, this._maskThreshold = h;
|
|
1194
1195
|
}
|
|
1195
1196
|
_head;
|
|
1196
1197
|
_labels;
|
|
@@ -1205,12 +1206,12 @@ class St extends it {
|
|
|
1205
1206
|
const s = e.head ?? "yolo-seg";
|
|
1206
1207
|
if (s !== "yolo-seg")
|
|
1207
1208
|
throw new Error(`Unsupported segmenter head '${s}'. Supported: 'yolo-seg'.`);
|
|
1208
|
-
const n = await X.create(t, e), r =
|
|
1209
|
+
const n = await X.create(t, e), r = st(e.labels ?? "coco", {
|
|
1209
1210
|
numClasses: e.numClasses
|
|
1210
1211
|
}), a = {};
|
|
1211
1212
|
for (let i = 0; i < r.length; i++)
|
|
1212
1213
|
a[i] = r[i];
|
|
1213
|
-
return new
|
|
1214
|
+
return new $t(
|
|
1214
1215
|
n,
|
|
1215
1216
|
s,
|
|
1216
1217
|
r,
|
|
@@ -1244,11 +1245,11 @@ class St extends it {
|
|
|
1244
1245
|
}
|
|
1245
1246
|
/** Run instance segmentation on a single image. */
|
|
1246
1247
|
async predict(t, e = {}) {
|
|
1247
|
-
const s = typeof t == "string" ? t : null, n = await
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1248
|
+
const s = typeof t == "string" ? t : null, n = await rt(t), { tensor: r, scale: a, padLeft: i, padTop: c } = this._preprocess(n), h = await this._session.run({ [this._session.inputName]: r }), { perAnchor: u, prototypes: d } = this._splitOutputs(h), l = Et(
|
|
1249
|
+
u.data,
|
|
1250
|
+
u.dims,
|
|
1251
|
+
d.data,
|
|
1252
|
+
d.dims,
|
|
1252
1253
|
{
|
|
1253
1254
|
numClasses: this._labels.length,
|
|
1254
1255
|
inputWidth: this._inputSize[0],
|
|
@@ -1263,28 +1264,28 @@ class St extends it {
|
|
|
1263
1264
|
maxDetections: this._maxDetections,
|
|
1264
1265
|
maskThreshold: this._maskThreshold
|
|
1265
1266
|
}
|
|
1266
|
-
),
|
|
1267
|
-
const
|
|
1268
|
-
return l.filter((
|
|
1267
|
+
), g = (e.classes !== void 0 ? (() => {
|
|
1268
|
+
const m = new Set(e.classes);
|
|
1269
|
+
return l.filter((x) => m.has(x.classId));
|
|
1269
1270
|
})() : l).map(
|
|
1270
|
-
(
|
|
1271
|
-
),
|
|
1271
|
+
(m) => this._buildResult(n, m.bbox, m.classId, m.confidence, m.mask)
|
|
1272
|
+
), f = [n.height, n.width];
|
|
1272
1273
|
return [
|
|
1273
|
-
new
|
|
1274
|
-
this._buildBoxes(
|
|
1275
|
-
this._buildMasks(
|
|
1276
|
-
|
|
1274
|
+
new Xt(
|
|
1275
|
+
this._buildBoxes(g, f),
|
|
1276
|
+
this._buildMasks(g, f),
|
|
1277
|
+
g,
|
|
1277
1278
|
this._names,
|
|
1278
1279
|
n,
|
|
1279
|
-
|
|
1280
|
+
f,
|
|
1280
1281
|
s
|
|
1281
1282
|
)
|
|
1282
1283
|
];
|
|
1283
1284
|
}
|
|
1284
1285
|
_preprocess(t) {
|
|
1285
|
-
const [e, s] = this._inputSize, n =
|
|
1286
|
+
const [e, s] = this._inputSize, n = St(t, e, s), r = at(n.image), a = Q(r, n.image.width, n.image.height, 3);
|
|
1286
1287
|
return {
|
|
1287
|
-
tensor:
|
|
1288
|
+
tensor: it(a, [1, 3, n.image.height, n.image.width]),
|
|
1288
1289
|
scale: n.scale,
|
|
1289
1290
|
padLeft: n.padLeft,
|
|
1290
1291
|
padTop: n.padTop
|
|
@@ -1307,41 +1308,41 @@ class St extends it {
|
|
|
1307
1308
|
return { perAnchor: e, prototypes: s };
|
|
1308
1309
|
}
|
|
1309
1310
|
_buildResult(t, e, s, n, r) {
|
|
1310
|
-
const [a, i, c,
|
|
1311
|
-
let
|
|
1312
|
-
if (l >
|
|
1313
|
-
const
|
|
1314
|
-
for (let
|
|
1315
|
-
const
|
|
1316
|
-
for (let
|
|
1317
|
-
if (r.data[
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1311
|
+
const [a, i, c, h] = e.asIntXyxy(), u = Math.max(0, a), d = Math.max(0, i), l = Math.min(t.width, c), y = Math.min(t.height, h);
|
|
1312
|
+
let g, f = r;
|
|
1313
|
+
if (l > u && y > d && r.data.length > 0) {
|
|
1314
|
+
const x = l - u, _ = y - d, p = Math.min(r.width, x), S = Math.min(r.height, _), A = new Uint8Array(p * S * 3);
|
|
1315
|
+
for (let M = 0; M < S; M++) {
|
|
1316
|
+
const v = ((d + M) * t.width + u) * 3, C = M * p * 3, k = M * r.width;
|
|
1317
|
+
for (let w = 0; w < p; w++)
|
|
1318
|
+
if (r.data[k + w] !== 0) {
|
|
1319
|
+
const I = v + w * 3, T = C + w * 3;
|
|
1320
|
+
A[T] = t.data[I], A[T + 1] = t.data[I + 1], A[T + 2] = t.data[I + 2];
|
|
1320
1321
|
}
|
|
1321
1322
|
}
|
|
1322
|
-
if (
|
|
1323
|
-
const
|
|
1324
|
-
for (let
|
|
1325
|
-
|
|
1326
|
-
r.data.subarray(
|
|
1327
|
-
|
|
1323
|
+
if (g = new D(A, p, S), p !== r.width || S !== r.height) {
|
|
1324
|
+
const M = new Uint8Array(p * S);
|
|
1325
|
+
for (let v = 0; v < S; v++)
|
|
1326
|
+
M.set(
|
|
1327
|
+
r.data.subarray(v * r.width, v * r.width + p),
|
|
1328
|
+
v * p
|
|
1328
1329
|
);
|
|
1329
|
-
|
|
1330
|
+
f = new Y(M, p, S);
|
|
1330
1331
|
}
|
|
1331
1332
|
} else
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1333
|
+
f = new Y(new Uint8Array(0), 0, 0), g = new D(new Uint8Array(0), 0, 0);
|
|
1334
|
+
const m = this._names[s] ?? `class_${s}`;
|
|
1334
1335
|
return {
|
|
1335
1336
|
classId: s,
|
|
1336
|
-
className:
|
|
1337
|
+
className: m,
|
|
1337
1338
|
confidence: n,
|
|
1338
1339
|
bbox: e,
|
|
1339
1340
|
cls: s,
|
|
1340
|
-
name:
|
|
1341
|
+
name: m,
|
|
1341
1342
|
conf: n,
|
|
1342
1343
|
box: e,
|
|
1343
|
-
mask:
|
|
1344
|
-
segmentedImage:
|
|
1344
|
+
mask: f,
|
|
1345
|
+
segmentedImage: g
|
|
1345
1346
|
};
|
|
1346
1347
|
}
|
|
1347
1348
|
_buildBoxes(t, e) {
|
|
@@ -1350,7 +1351,7 @@ class St extends it {
|
|
|
1350
1351
|
const c = t[i];
|
|
1351
1352
|
n[i * 4] = c.bbox.x1, n[i * 4 + 1] = c.bbox.y1, n[i * 4 + 2] = c.bbox.x2, n[i * 4 + 3] = c.bbox.y2, r[i] = c.classId, a[i] = c.confidence;
|
|
1352
1353
|
}
|
|
1353
|
-
return new
|
|
1354
|
+
return new Mt(n, r, a, e);
|
|
1354
1355
|
}
|
|
1355
1356
|
_buildMasks(t, e) {
|
|
1356
1357
|
const s = new Float32Array(t.length * 4);
|
|
@@ -1358,59 +1359,203 @@ class St extends it {
|
|
|
1358
1359
|
const r = t[n];
|
|
1359
1360
|
s[n * 4] = r.bbox.x1, s[n * 4 + 1] = r.bbox.y1, s[n * 4 + 2] = r.bbox.x2, s[n * 4 + 3] = r.bbox.y2;
|
|
1360
1361
|
}
|
|
1361
|
-
return new
|
|
1362
|
+
return new Rt(
|
|
1362
1363
|
t.map((n) => n.mask),
|
|
1363
1364
|
s,
|
|
1364
1365
|
e
|
|
1365
1366
|
);
|
|
1366
1367
|
}
|
|
1367
1368
|
}
|
|
1368
|
-
const
|
|
1369
|
+
const we = "0.2.1", xt = {
|
|
1370
|
+
video: {
|
|
1371
|
+
facingMode: { ideal: "environment" },
|
|
1372
|
+
width: { ideal: 1920 },
|
|
1373
|
+
height: { ideal: 1080 }
|
|
1374
|
+
},
|
|
1375
|
+
audio: !1
|
|
1376
|
+
};
|
|
1377
|
+
function bt(o) {
|
|
1378
|
+
if (typeof window > "u")
|
|
1379
|
+
return { kind: "unsupported", message: "Camera is unavailable in this environment." };
|
|
1380
|
+
if (!window.isSecureContext)
|
|
1381
|
+
return {
|
|
1382
|
+
kind: "insecure",
|
|
1383
|
+
message: "Camera access requires a secure (HTTPS) connection."
|
|
1384
|
+
};
|
|
1385
|
+
if (o instanceof DOMException)
|
|
1386
|
+
switch (o.name) {
|
|
1387
|
+
case "NotAllowedError":
|
|
1388
|
+
case "SecurityError":
|
|
1389
|
+
return {
|
|
1390
|
+
kind: "permission-denied",
|
|
1391
|
+
message: "Camera permission denied. Enable access in your browser settings."
|
|
1392
|
+
};
|
|
1393
|
+
case "NotFoundError":
|
|
1394
|
+
case "OverconstrainedError":
|
|
1395
|
+
return {
|
|
1396
|
+
kind: "no-camera",
|
|
1397
|
+
message: "No camera available on this device."
|
|
1398
|
+
};
|
|
1399
|
+
case "NotReadableError":
|
|
1400
|
+
case "AbortError":
|
|
1401
|
+
return {
|
|
1402
|
+
kind: "in-use",
|
|
1403
|
+
message: "The camera is in use by another app. Close it and try again."
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
return {
|
|
1407
|
+
kind: "unknown",
|
|
1408
|
+
message: o instanceof Error ? o.message : "Unexpected error while accessing the camera."
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
function ye(o = {}) {
|
|
1412
|
+
const [t, e] = K("loading"), [s, n] = K(null), [r, a] = K(0), i = tt(null), c = tt(
|
|
1413
|
+
o.constraints ?? xt
|
|
1414
|
+
);
|
|
1415
|
+
return c.current = o.constraints ?? xt, _t(() => {
|
|
1416
|
+
let h = !1, u = null, d = null;
|
|
1417
|
+
async function l() {
|
|
1418
|
+
if (e("loading"), n(null), typeof navigator > "u" || !navigator.mediaDevices || typeof navigator.mediaDevices.getUserMedia != "function") {
|
|
1419
|
+
h || (n(
|
|
1420
|
+
typeof window < "u" && !window.isSecureContext ? bt(null) : {
|
|
1421
|
+
kind: "unsupported",
|
|
1422
|
+
message: "Camera capture is not supported in this browser."
|
|
1423
|
+
}
|
|
1424
|
+
), e("error"));
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
try {
|
|
1428
|
+
if (u = await navigator.mediaDevices.getUserMedia(c.current), h) {
|
|
1429
|
+
u.getTracks().forEach((g) => g.stop());
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const y = i.current;
|
|
1433
|
+
if (!y) {
|
|
1434
|
+
u.getTracks().forEach((g) => g.stop());
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
d = y, y.srcObject = u, await y.play().catch(() => {
|
|
1438
|
+
}), h || e("ready");
|
|
1439
|
+
} catch (y) {
|
|
1440
|
+
h || (n(bt(y)), e("error"));
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return l(), () => {
|
|
1444
|
+
h = !0, u && u.getTracks().forEach((y) => y.stop()), d && (d.srcObject = null);
|
|
1445
|
+
};
|
|
1446
|
+
}, [r]), {
|
|
1447
|
+
status: t,
|
|
1448
|
+
error: s,
|
|
1449
|
+
videoRef: i,
|
|
1450
|
+
retry: () => a((h) => h + 1)
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
const oe = 256;
|
|
1454
|
+
function re(o) {
|
|
1455
|
+
return o instanceof HTMLVideoElement ? { width: o.videoWidth, height: o.videoHeight } : o instanceof HTMLCanvasElement ? { width: o.width, height: o.height } : {
|
|
1456
|
+
width: o.naturalWidth || o.width,
|
|
1457
|
+
height: o.naturalHeight || o.height
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
function ae(o, t) {
|
|
1461
|
+
const { width: e, height: s } = re(o);
|
|
1462
|
+
if (e === 0 || s === 0) return 0;
|
|
1463
|
+
const n = Math.min(1, oe / Math.max(e, s)), r = Math.max(1, Math.round(e * n)), a = Math.max(1, Math.round(s * n)), i = t ?? document.createElement("canvas");
|
|
1464
|
+
i.width = r, i.height = a;
|
|
1465
|
+
const c = i.getContext("2d", { willReadFrequently: !0 });
|
|
1466
|
+
if (!c) return 0;
|
|
1467
|
+
c.drawImage(o, 0, 0, r, a);
|
|
1468
|
+
const h = c.getImageData(0, 0, r, a).data;
|
|
1469
|
+
let u = 0;
|
|
1470
|
+
const d = r * a;
|
|
1471
|
+
for (let l = 0; l < h.length; l += 4)
|
|
1472
|
+
u += 0.2126 * h[l] + 0.7152 * h[l + 1] + 0.0722 * h[l + 2];
|
|
1473
|
+
return u / d;
|
|
1474
|
+
}
|
|
1475
|
+
function ge(o, t) {
|
|
1476
|
+
return o >= t;
|
|
1477
|
+
}
|
|
1478
|
+
class pe extends Error {
|
|
1479
|
+
/** Measured mean luminance, `0..255`. */
|
|
1480
|
+
luminance;
|
|
1481
|
+
/** Threshold that was checked against, `0..255`. */
|
|
1482
|
+
threshold;
|
|
1483
|
+
/**
|
|
1484
|
+
* @param luminance - the measured mean luminance in `0..255`.
|
|
1485
|
+
* @param threshold - the threshold the measurement failed to reach.
|
|
1486
|
+
*/
|
|
1487
|
+
constructor(t, e) {
|
|
1488
|
+
super("Image is too dark to analyse. Capture again in a brighter environment."), this.name = "LowLuminanceError", this.luminance = t, this.threshold = e;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
function xe(o, { enabled: t = !0, intervalMs: e = 160 } = {}) {
|
|
1492
|
+
const [s, n] = K(0), r = tt(null);
|
|
1493
|
+
return _t(() => {
|
|
1494
|
+
if (!t || typeof window > "u") return;
|
|
1495
|
+
r.current || (r.current = document.createElement("canvas"));
|
|
1496
|
+
let a = 0, i = 0;
|
|
1497
|
+
const c = (h) => {
|
|
1498
|
+
const u = o.current;
|
|
1499
|
+
if (!u || u.readyState < 2 || u.videoWidth === 0) {
|
|
1500
|
+
a = window.requestAnimationFrame(c);
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
h - i >= e && (i = h, n(ae(u, r.current ?? void 0))), a = window.requestAnimationFrame(c);
|
|
1504
|
+
};
|
|
1505
|
+
return a = window.requestAnimationFrame(c), () => window.cancelAnimationFrame(a);
|
|
1506
|
+
}, [o, t, e]), s;
|
|
1507
|
+
}
|
|
1369
1508
|
export {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1509
|
+
vt as BoundingBox,
|
|
1510
|
+
Mt as Boxes,
|
|
1511
|
+
Vt as COCO_CLASSES,
|
|
1512
|
+
Bt as ClassificationResults,
|
|
1513
|
+
Ct as Classifier,
|
|
1514
|
+
mt as DEFAULT_PROVIDERS,
|
|
1515
|
+
Yt as DetectionResults,
|
|
1516
|
+
kt as Detector,
|
|
1517
|
+
E as ImageLoadError,
|
|
1518
|
+
ut as InferenceError,
|
|
1519
|
+
oe as LUMINANCE_SAMPLE_MAX_EDGE,
|
|
1520
|
+
q as LabelMapError,
|
|
1521
|
+
pe as LowLuminanceError,
|
|
1522
|
+
Y as Mask,
|
|
1523
|
+
Rt as Masks,
|
|
1524
|
+
zt as ModelLoadError,
|
|
1384
1525
|
X as OrtSession,
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1526
|
+
B as OrtVisionError,
|
|
1527
|
+
Ut as Probs,
|
|
1528
|
+
ce as ProviderNotAvailableError,
|
|
1529
|
+
D as RGBImage,
|
|
1530
|
+
Xt as SegmentationResults,
|
|
1531
|
+
$t as Segmenter,
|
|
1532
|
+
we as VERSION,
|
|
1533
|
+
ht as VisionTask,
|
|
1534
|
+
Wt as batchedNms,
|
|
1535
|
+
ae as computeImageLuminance,
|
|
1536
|
+
Tt as decodeYolo,
|
|
1537
|
+
ct as decodeYoloAnchors,
|
|
1538
|
+
Et as decodeYoloSeg,
|
|
1539
|
+
ue as decodeYoloV8,
|
|
1540
|
+
fe as decodeYoloV8Anchors,
|
|
1541
|
+
me as decodeYoloV8Seg,
|
|
1542
|
+
le as fromCv2,
|
|
1543
|
+
ge as isLuminanceAcceptable,
|
|
1544
|
+
St as letterbox,
|
|
1545
|
+
rt as loadImage,
|
|
1546
|
+
Zt as nms,
|
|
1547
|
+
Jt as normalize,
|
|
1548
|
+
It as resize,
|
|
1549
|
+
st as resolveLabels,
|
|
1550
|
+
Pt as resolveProviders,
|
|
1551
|
+
qt as softmax,
|
|
1409
1552
|
Q as toCHW,
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1553
|
+
de as toCv2,
|
|
1554
|
+
at as toFloat32,
|
|
1555
|
+
it as toFloat32Tensor,
|
|
1556
|
+
he as toTensor,
|
|
1557
|
+
Qt as topK,
|
|
1558
|
+
ye as useCameraStream,
|
|
1559
|
+
xe as useLiveLuminance
|
|
1415
1560
|
};
|
|
1416
1561
|
//# sourceMappingURL=vision.js.map
|