seg-cam 0.1.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/LICENSE ADDED
@@ -0,0 +1,438 @@
1
+
2
+ Attribution-NonCommercial-ShareAlike 4.0 International
3
+
4
+ =======================================================================
5
+
6
+ Creative Commons Corporation ("Creative Commons") is not a law firm and
7
+ does not provide legal services or legal advice. Distribution of
8
+ Creative Commons public licenses does not create a lawyer-client or
9
+ other relationship. Creative Commons makes its licenses and related
10
+ information available on an "as-is" basis. Creative Commons gives no
11
+ warranties regarding its licenses, any material licensed under their
12
+ terms and conditions, or any related information. Creative Commons
13
+ disclaims all liability for damages resulting from their use to the
14
+ fullest extent possible.
15
+
16
+ Using Creative Commons Public Licenses
17
+
18
+ Creative Commons public licenses provide a standard set of terms and
19
+ conditions that creators and other rights holders may use to share
20
+ original works of authorship and other material subject to copyright
21
+ and certain other rights specified in the public license below. The
22
+ following considerations are for informational purposes only, are not
23
+ exhaustive, and do not form part of our licenses.
24
+
25
+ Considerations for licensors: Our public licenses are
26
+ intended for use by those authorized to give the public
27
+ permission to use material in ways otherwise restricted by
28
+ copyright and certain other rights. Our licenses are
29
+ irrevocable. Licensors should read and understand the terms
30
+ and conditions of the license they choose before applying it.
31
+ Licensors should also secure all rights necessary before
32
+ applying our licenses so that the public can reuse the
33
+ material as expected. Licensors should clearly mark any
34
+ material not subject to the license. This includes other CC-
35
+ licensed material, or material used under an exception or
36
+ limitation to copyright. More considerations for licensors:
37
+ wiki.creativecommons.org/Considerations_for_licensors
38
+
39
+ Considerations for the public: By using one of our public
40
+ licenses, a licensor grants the public permission to use the
41
+ licensed material under specified terms and conditions. If
42
+ the licensor's permission is not necessary for any reason--for
43
+ example, because of any applicable exception or limitation to
44
+ copyright--then that use is not regulated by the license. Our
45
+ licenses grant only permissions under copyright and certain
46
+ other rights that a licensor has authority to grant. Use of
47
+ the licensed material may still be restricted for other
48
+ reasons, including because others have copyright or other
49
+ rights in the material. A licensor may make special requests,
50
+ such as asking that all changes be marked or described.
51
+ Although not required by our licenses, you are encouraged to
52
+ respect those requests where reasonable. More considerations
53
+ for the public:
54
+ wiki.creativecommons.org/Considerations_for_licensees
55
+
56
+ =======================================================================
57
+
58
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
59
+ Public License
60
+
61
+ By exercising the Licensed Rights (defined below), You accept and agree
62
+ to be bound by the terms and conditions of this Creative Commons
63
+ Attribution-NonCommercial-ShareAlike 4.0 International Public License
64
+ ("Public License"). To the extent this Public License may be
65
+ interpreted as a contract, You are granted the Licensed Rights in
66
+ consideration of Your acceptance of these terms and conditions, and the
67
+ Licensor grants You such rights in consideration of benefits the
68
+ Licensor receives from making the Licensed Material available under
69
+ these terms and conditions.
70
+
71
+
72
+ Section 1 -- Definitions.
73
+
74
+ a. Adapted Material means material subject to Copyright and Similar
75
+ Rights that is derived from or based upon the Licensed Material
76
+ and in which the Licensed Material is translated, altered,
77
+ arranged, transformed, or otherwise modified in a manner requiring
78
+ permission under the Copyright and Similar Rights held by the
79
+ Licensor. For purposes of this Public License, where the Licensed
80
+ Material is a musical work, performance, or sound recording,
81
+ Adapted Material is always produced where the Licensed Material is
82
+ synched in timed relation with a moving image.
83
+
84
+ b. Adapter's License means the license You apply to Your Copyright
85
+ and Similar Rights in Your contributions to Adapted Material in
86
+ accordance with the terms and conditions of this Public License.
87
+
88
+ c. BY-NC-SA Compatible License means a license listed at
89
+ creativecommons.org/compatiblelicenses, approved by Creative
90
+ Commons as essentially the equivalent of this Public License.
91
+
92
+ d. Copyright and Similar Rights means copyright and/or similar rights
93
+ closely related to copyright including, without limitation,
94
+ performance, broadcast, sound recording, and Sui Generis Database
95
+ Rights, without regard to how the rights are labeled or
96
+ categorized. For purposes of this Public License, the rights
97
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
98
+ Rights.
99
+
100
+ e. Effective Technological Measures means those measures that, in the
101
+ absence of proper authority, may not be circumvented under laws
102
+ fulfilling obligations under Article 11 of the WIPO Copyright
103
+ Treaty adopted on December 20, 1996, and/or similar international
104
+ agreements.
105
+
106
+ f. Exceptions and Limitations means fair use, fair dealing, and/or
107
+ any other exception or limitation to Copyright and Similar Rights
108
+ that applies to Your use of the Licensed Material.
109
+
110
+ g. License Elements means the license attributes listed in the name
111
+ of a Creative Commons Public License. The License Elements of this
112
+ Public License are Attribution, NonCommercial, and ShareAlike.
113
+
114
+ h. Licensed Material means the artistic or literary work, database,
115
+ or other material to which the Licensor applied this Public
116
+ License.
117
+
118
+ i. Licensed Rights means the rights granted to You subject to the
119
+ terms and conditions of this Public License, which are limited to
120
+ all Copyright and Similar Rights that apply to Your use of the
121
+ Licensed Material and that the Licensor has authority to license.
122
+
123
+ j. Licensor means the individual(s) or entity(ies) granting rights
124
+ under this Public License.
125
+
126
+ k. NonCommercial means not primarily intended for or directed towards
127
+ commercial advantage or monetary compensation. For purposes of
128
+ this Public License, the exchange of the Licensed Material for
129
+ other material subject to Copyright and Similar Rights by digital
130
+ file-sharing or similar means is NonCommercial provided there is
131
+ no payment of monetary compensation in connection with the
132
+ exchange.
133
+
134
+ l. Share means to provide material to the public by any means or
135
+ process that requires permission under the Licensed Rights, such
136
+ as reproduction, public display, public performance, distribution,
137
+ dissemination, communication, or importation, and to make material
138
+ available to the public including in ways that members of the
139
+ public may access the material from a place and at a time
140
+ individually chosen by them.
141
+
142
+ m. Sui Generis Database Rights means rights other than copyright
143
+ resulting from Directive 96/9/EC of the European Parliament and of
144
+ the Council of 11 March 1996 on the legal protection of databases,
145
+ as amended and/or succeeded, as well as other essentially
146
+ equivalent rights anywhere in the world.
147
+
148
+ n. You means the individual or entity exercising the Licensed Rights
149
+ under this Public License. Your has a corresponding meaning.
150
+
151
+
152
+ Section 2 -- Scope.
153
+
154
+ a. License grant.
155
+
156
+ 1. Subject to the terms and conditions of this Public License,
157
+ the Licensor hereby grants You a worldwide, royalty-free,
158
+ non-sublicensable, non-exclusive, irrevocable license to
159
+ exercise the Licensed Rights in the Licensed Material to:
160
+
161
+ a. reproduce and Share the Licensed Material, in whole or
162
+ in part, for NonCommercial purposes only; and
163
+
164
+ b. produce, reproduce, and Share Adapted Material for
165
+ NonCommercial purposes only.
166
+
167
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
168
+ Exceptions and Limitations apply to Your use, this Public
169
+ License does not apply, and You do not need to comply with
170
+ its terms and conditions.
171
+
172
+ 3. Term. The term of this Public License is specified in Section
173
+ 6(a).
174
+
175
+ 4. Media and formats; technical modifications allowed. The
176
+ Licensor authorizes You to exercise the Licensed Rights in
177
+ all media and formats whether now known or hereafter created,
178
+ and to make technical modifications necessary to do so. The
179
+ Licensor waives and/or agrees not to assert any right or
180
+ authority to forbid You from making technical modifications
181
+ necessary to exercise the Licensed Rights, including
182
+ technical modifications necessary to circumvent Effective
183
+ Technological Measures. For purposes of this Public License,
184
+ simply making modifications authorized by this Section 2(a)
185
+ (4) never produces Adapted Material.
186
+
187
+ 5. Downstream recipients.
188
+
189
+ a. Offer from the Licensor -- Licensed Material. Every
190
+ recipient of the Licensed Material automatically
191
+ receives an offer from the Licensor to exercise the
192
+ Licensed Rights under the terms and conditions of this
193
+ Public License.
194
+
195
+ b. Additional offer from the Licensor -- Adapted Material.
196
+ Every recipient of Adapted Material from You
197
+ automatically receives an offer from the Licensor to
198
+ exercise the Licensed Rights in the Adapted Material
199
+ under the conditions of the Adapter's License You apply.
200
+
201
+ c. No downstream restrictions. You may not offer or impose
202
+ any additional or different terms or conditions on, or
203
+ apply any Effective Technological Measures to, the
204
+ Licensed Material if doing so restricts exercise of the
205
+ Licensed Rights by any recipient of the Licensed
206
+ Material.
207
+
208
+ 6. No endorsement. Nothing in this Public License constitutes or
209
+ may be construed as permission to assert or imply that You
210
+ are, or that Your use of the Licensed Material is, connected
211
+ with, or sponsored, endorsed, or granted official status by,
212
+ the Licensor or others designated to receive attribution as
213
+ provided in Section 3(a)(1)(A)(i).
214
+
215
+ b. Other rights.
216
+
217
+ 1. Moral rights, such as the right of integrity, are not
218
+ licensed under this Public License, nor are publicity,
219
+ privacy, and/or other similar personality rights; however, to
220
+ the extent possible, the Licensor waives and/or agrees not to
221
+ assert any such rights held by the Licensor to the limited
222
+ extent necessary to allow You to exercise the Licensed
223
+ Rights, but not otherwise.
224
+
225
+ 2. Patent and trademark rights are not licensed under this
226
+ Public License.
227
+
228
+ 3. To the extent possible, the Licensor waives any right to
229
+ collect royalties from You for the exercise of the Licensed
230
+ Rights, whether directly or through a collecting society
231
+ under any voluntary or waivable statutory or compulsory
232
+ licensing scheme. In all other cases the Licensor expressly
233
+ reserves any right to collect such royalties, including when
234
+ the Licensed Material is used other than for NonCommercial
235
+ purposes.
236
+
237
+
238
+ Section 3 -- License Conditions.
239
+
240
+ Your exercise of the Licensed Rights is expressly made subject to the
241
+ following conditions.
242
+
243
+ a. Attribution.
244
+
245
+ 1. If You Share the Licensed Material (including in modified
246
+ form), You must:
247
+
248
+ a. retain the following if it is supplied by the Licensor
249
+ with the Licensed Material:
250
+
251
+ i. identification of the creator(s) of the Licensed
252
+ Material and any others designated to receive
253
+ attribution, in any reasonable manner requested by
254
+ the Licensor (including by pseudonym if
255
+ designated);
256
+
257
+ ii. a copyright notice;
258
+
259
+ iii. a notice that refers to this Public License;
260
+
261
+ iv. a notice that refers to the disclaimer of
262
+ warranties;
263
+
264
+ v. a URI or hyperlink to the Licensed Material to the
265
+ extent reasonably practicable;
266
+
267
+ b. indicate if You modified the Licensed Material and
268
+ retain an indication of any previous modifications; and
269
+
270
+ c. indicate the Licensed Material is licensed under this
271
+ Public License, and include the text of, or the URI or
272
+ hyperlink to, this Public License.
273
+
274
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
275
+ reasonable manner based on the medium, means, and context in
276
+ which You Share the Licensed Material. For example, it may be
277
+ reasonable to satisfy the conditions by providing a URI or
278
+ hyperlink to a resource that includes the required
279
+ information.
280
+ 3. If requested by the Licensor, You must remove any of the
281
+ information required by Section 3(a)(1)(A) to the extent
282
+ reasonably practicable.
283
+
284
+ b. ShareAlike.
285
+
286
+ In addition to the conditions in Section 3(a), if You Share
287
+ Adapted Material You produce, the following conditions also apply.
288
+
289
+ 1. The Adapter's License You apply must be a Creative Commons
290
+ license with the same License Elements, this version or
291
+ later, or a BY-NC-SA Compatible License.
292
+
293
+ 2. You must include the text of, or the URI or hyperlink to, the
294
+ Adapter's License You apply. You may satisfy this condition
295
+ in any reasonable manner based on the medium, means, and
296
+ context in which You Share Adapted Material.
297
+
298
+ 3. You may not offer or impose any additional or different terms
299
+ or conditions on, or apply any Effective Technological
300
+ Measures to, Adapted Material that restrict exercise of the
301
+ rights granted under the Adapter's License You apply.
302
+
303
+
304
+ Section 4 -- Sui Generis Database Rights.
305
+
306
+ Where the Licensed Rights include Sui Generis Database Rights that
307
+ apply to Your use of the Licensed Material:
308
+
309
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
310
+ to extract, reuse, reproduce, and Share all or a substantial
311
+ portion of the contents of the database for NonCommercial purposes
312
+ only;
313
+
314
+ b. if You include all or a substantial portion of the database
315
+ contents in a database in which You have Sui Generis Database
316
+ Rights, then the database in which You have Sui Generis Database
317
+ Rights (but not its individual contents) is Adapted Material,
318
+ including for purposes of Section 3(b); and
319
+
320
+ c. You must comply with the conditions in Section 3(a) if You Share
321
+ all or a substantial portion of the contents of the database.
322
+
323
+ For the avoidance of doubt, this Section 4 supplements and does not
324
+ replace Your obligations under this Public License where the Licensed
325
+ Rights include other Copyright and Similar Rights.
326
+
327
+
328
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
329
+
330
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
331
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
332
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
333
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
334
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
335
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
336
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
337
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
338
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
339
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
340
+
341
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
342
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
343
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
344
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
345
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
346
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
347
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
348
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
349
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
350
+
351
+ c. The disclaimer of warranties and limitation of liability provided
352
+ above shall be interpreted in a manner that, to the extent
353
+ possible, most closely approximates an absolute disclaimer and
354
+ waiver of all liability.
355
+
356
+
357
+ Section 6 -- Term and Termination.
358
+
359
+ a. This Public License applies for the term of the Copyright and
360
+ Similar Rights licensed here. However, if You fail to comply with
361
+ this Public License, then Your rights under this Public License
362
+ terminate automatically.
363
+
364
+ b. Where Your right to use the Licensed Material has terminated under
365
+ Section 6(a), it reinstates:
366
+
367
+ 1. automatically as of the date the violation is cured, provided
368
+ it is cured within 30 days of Your discovery of the
369
+ violation; or
370
+
371
+ 2. upon express reinstatement by the Licensor.
372
+
373
+ For the avoidance of doubt, this Section 6(b) does not affect any
374
+ right the Licensor may have to seek remedies for Your violations
375
+ of this Public License.
376
+
377
+ c. For the avoidance of doubt, the Licensor may also offer the
378
+ Licensed Material under separate terms or conditions or stop
379
+ distributing the Licensed Material at any time; however, doing so
380
+ will not terminate this Public License.
381
+
382
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
383
+ License.
384
+
385
+
386
+ Section 7 -- Other Terms and Conditions.
387
+
388
+ a. The Licensor shall not be bound by any additional or different
389
+ terms or conditions communicated by You unless expressly agreed.
390
+
391
+ b. Any arrangements, understandings, or agreements regarding the
392
+ Licensed Material not stated herein are separate from and
393
+ independent of the terms and conditions of this Public License.
394
+
395
+
396
+ Section 8 -- Interpretation.
397
+
398
+ a. For the avoidance of doubt, this Public License does not, and
399
+ shall not be interpreted to, reduce, limit, restrict, or impose
400
+ conditions on any use of the Licensed Material that could lawfully
401
+ be made without permission under this Public License.
402
+
403
+ b. To the extent possible, if any provision of this Public License is
404
+ deemed unenforceable, it shall be automatically reformed to the
405
+ minimum extent necessary to make it enforceable. If the provision
406
+ cannot be reformed, it shall be severed from this Public License
407
+ without affecting the enforceability of the remaining terms and
408
+ conditions.
409
+
410
+ c. No term or condition of this Public License will be waived and no
411
+ failure to comply consented to unless expressly agreed to by the
412
+ Licensor.
413
+
414
+ d. Nothing in this Public License constitutes or may be interpreted
415
+ as a limitation upon, or waiver of, any privileges and immunities
416
+ that apply to the Licensor or You, including from the legal
417
+ processes of any jurisdiction or authority.
418
+
419
+ =======================================================================
420
+
421
+ Creative Commons is not a party to its public
422
+ licenses. Notwithstanding, Creative Commons may elect to apply one of
423
+ its public licenses to material it publishes and in those instances
424
+ will be considered the “Licensor.” The text of the Creative Commons
425
+ public licenses is dedicated to the public domain under the CC0 Public
426
+ Domain Dedication. Except for the limited purpose of indicating that
427
+ material is shared under a Creative Commons public license or as
428
+ otherwise permitted by the Creative Commons policies published at
429
+ creativecommons.org/policies, Creative Commons does not authorize the
430
+ use of the trademark "Creative Commons" or any other trademark or logo
431
+ of Creative Commons without its prior written consent including,
432
+ without limitation, in connection with any unauthorized modifications
433
+ to any of its public licenses or any other arrangements,
434
+ understandings, or agreements concerning use of licensed material. For
435
+ the avoidance of doubt, this paragraph does not form part of the
436
+ public licenses.
437
+
438
+ Creative Commons may be contacted at creativecommons.org.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # seg-cam
2
+
3
+ An easy-to-use drop-in library that wraps around TensorFlow.js BodyPix. Using it is as simple as passing a video reference to the `JerseyDetector` component.
4
+
5
+ `seg-cam` was create for real-time video processing, for example to detect the shirts of users in a video stream.
6
+
7
+ ## Features
8
+
9
+ - **Live Segmentation**: High-performance person and body part segmentation.
10
+ - **Self-Contained Worker**: Fully bundled Web Worker for background processing, ensuring zero UI lag.
11
+ - **CSP Compliant**: No external CDNs or `importScripts` used at runtime.
12
+ - **Highly Configurable**: Control architecture, thresholds, and target body parts.
13
+ - **React Ready**: Optimized for React with a simple component and hook API.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ### 1. Install the Library
20
+
21
+ ```bash
22
+ npm install seg-cam
23
+ # or
24
+ pnpm add seg-cam
25
+ ```
26
+
27
+ ### 2. Setup the Web Worker
28
+
29
+ Because the heavy ML processing happens in a Web Worker, you must provide the worker file. When you build the project or install it, the worker bundle is available at:
30
+ `node_modules/seg-cam/public/jersey-detector-worker.js` (for dev) or `node_modules/seg-cam/dist/jersey-detector-worker.js` (for production).
31
+
32
+ **Option A: Copy to your public folder (Recommended)**
33
+ Copy `jersey-detector-worker.js` to your project's `public/` folder so it can be served at exactly `/jersey-detector-worker.js`.
34
+
35
+ **Option B: Custom Hosting**
36
+ Host the worker file anywhere and pass the URL to the component using the `workerUrl` prop.
37
+
38
+ ---
39
+
40
+ ## Usage
41
+
42
+ ```tsx
43
+ import { useRef, useState } from 'react';
44
+ import { JerseyDetector } from 'seg-cam';
45
+
46
+ export function CameraApp() {
47
+ const videoRef = useRef<HTMLVideoElement>(null);
48
+ const [stats, setStats] = useState(null);
49
+
50
+ return (
51
+ <div>
52
+ <video ref={videoRef} autoPlay muted playsInline />
53
+
54
+ <JerseyDetector
55
+ videoRef={videoRef}
56
+ workerUrl="/jersey-detector-worker.js" // Path to your hosted worker file
57
+ onStatsUpdate={(newStats) => setStats(newStats)}
58
+ threshold={0.6}
59
+ targetPartId={2}
60
+ />
61
+
62
+ {stats && (
63
+ <div>
64
+ Jerseys Found: {stats.jerseyCount} | FPS: {stats.fps}
65
+ </div>
66
+ )}
67
+ </div>
68
+ );
69
+ }
70
+ ```
71
+
72
+ ---
73
+
74
+ ## API Reference
75
+
76
+ ### `JerseyDetector` Props
77
+
78
+ | Prop | Type | Default | Description |
79
+ | :--- | :--- | :--- | :--- |
80
+ | `videoRef` | `React.RefObject<HTMLVideoElement>` | **Required** | Reference to the video source to process. |
81
+ | `workerUrl` | `string` | `'/jersey-detector-worker.js'` | URL to the bundled worker JS file. |
82
+ | `threshold` | `number` | `0.5` | Confidence threshold for detection (0 to 1). |
83
+ | `targetPartId` | `number` | `12` | BodyPix Part ID to isolate (12 = Torso). |
84
+ | `onlyDrawMask` | `boolean` | `true` | If true, returns only the overlay mask for the input video. If false, includes a copy of the input frame.|
85
+ | `onStatsUpdate`| `(stats: DetectionStats) => void` | - | Callback triggered on every processed frame with stats. |
86
+ | `onWorkerReady`| `(ready: boolean) => void` | - | Callback triggered when the TFJS model is loaded. |
87
+ | `onWorkerError`| `(error: string \| null) => void` | - | Callback triggered if the worker fails to initialize. |
88
+ | `onSegmentedImage`| `(images: ImageBitmap[]) => void`| - | Callback returning individual bitmaps of detected objects. |
89
+ | `bodyPixArchitecture`| `'MobileNetV1' \| 'ResNet50'` | `'MobileNetV1'` | Performance vs Accuracy trade-off. |
90
+ | `verbose` | `boolean` | `false` | Enable detailed console logging. |
91
+
92
+ ### `DetectionStats` Type
93
+
94
+ ```typescript
95
+ interface DetectionStats {
96
+ jerseyCount: number; // Number of unique jerseys detected
97
+ confidence: number; // Average confidence score
98
+ processingTime: number; // Time spent on CPU in ms per frame
99
+ fps: number; // Real-time processing FPS
100
+ }
101
+ ```
102
+
103
+ ### `JerseyDetectorHandle` (Inverted Ref)
104
+
105
+ You can use a `ref` on the `JerseyDetector` component to access its internal state imperatively:
106
+
107
+ ```tsx
108
+ const detectorRef = useRef<JerseyDetectorHandle>(null);
109
+
110
+ // Access current state:
111
+ const isReady = detectorRef.current?.isReady;
112
+ const currentStats = detectorRef.current?.stats;
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Advanced Configuration
118
+
119
+ `seg-cam` uses **BodyPix** under the hood. You can fine-tune the detection and rendering by passing these props:
120
+
121
+ ### Model Parameters
122
+ - **`bodyPixArchitecture`**: (`'MobileNetV1' | 'ResNet50'`) MobileNet is faster; ResNet is more accurate.
123
+ - **`bodyPixMultiplier`**: (`0.5, 0.75, 1.0`) The internal width of the model's layers. Smaller is faster.
124
+ - **`bodyPixStride`**: (`8, 16, 32`) The output stride. Smaller is more accurate but slower.
125
+ - **`bodyPixQuantBytes`**: (`1, 2, 4`) Quantization level. 2 is a good balance.
126
+ - **`multiSegmentation`**: (`boolean`, Default `true`) Whether to detect multiple people simultaneously.
127
+ - **`segmentBodyParts`**: (`boolean`, Default `true`) Whether to compute specific body part IDs.
128
+
129
+ ### Rendering & Masking
130
+ - **`targetPartId`**: (`number`, Default `12`) The BodyPix part ID to treat as the "Jersey". (e.g., 12=torso, 2=full upper body).
131
+ - **`backgroundShade`**: (`number`, 0-255, Default `0`) The alpha/opacity for non-jersey pixels.
132
+ - **`shirtShade`**: (`number`, 0-255, Default `170`) The alpha/opacity for the detected jersey pixels.
133
+ - **`onlyDrawMask`**: (`boolean`, Default `true`)
134
+ - `true`: Returns only the overlay mask (useful for custom stacking).
135
+ - `false`: Includes a copy of the input frame underneath the mask.
136
+ - **`threshold`**: (`number`, 0.0-1.0, Default `0.5`) The minimum confidence required for a person pixel to be considered valid.
137
+
138
+ ## Acknowledgements
139
+
140
+ This project is powered by **TensorFlow.js** and the **BodyPix** model.
141
+ Detailed attributions for third-party software and models can be found in the [NOTICE](./NOTICE) file.
142
+
143
+ ## License
144
+
145
+ Copyright © 2026 [Seg-Cam Team].
146
+ Licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](./LICENSE).