File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed
examples/bodySegmentation-select-body-parts Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -32,12 +32,11 @@ function draw() {
32
32
background ( 255 ) ;
33
33
image ( video , 0 , 0 ) ;
34
34
if ( segmentation ) {
35
+ let parts = bodySegmentation . getPartsId ( ) ;
35
36
let gridSize = 10 ;
36
37
for ( let x = 0 ; x < video . width ; x += gridSize ) {
37
38
for ( let y = 0 ; y < video . height ; y += gridSize ) {
38
- if (
39
- segmentation . data [ y * video . width + x ] == bodySegmentation . TORSO_FRONT
40
- ) {
39
+ if ( segmentation . data [ y * video . width + x ] == parts . TORSO_FRONT ) {
41
40
fill ( 255 , 0 , 0 ) ;
42
41
noStroke ( ) ;
43
42
circle ( x , y , gridSize ) ;
Original file line number Diff line number Diff line change @@ -131,10 +131,14 @@ class BodySegmentation {
131
131
"bodySegmentation"
132
132
) ;
133
133
134
- // add body part constants to the instance variable
135
- for ( let key in BODYPIX_PALETTE ) {
136
- this [ key ] = BODYPIX_PALETTE [ key ] . id ;
137
- }
134
+ // Add function to return parts' key and id
135
+ this . getPartsId = ( ) => {
136
+ let parts = { } ;
137
+ for ( let key in BODYPIX_PALETTE ) {
138
+ parts [ key ] = BODYPIX_PALETTE [ key ] . id ;
139
+ }
140
+ return parts ;
141
+ } ;
138
142
} else {
139
143
pipeline = tfBodySegmentation . SupportedModels . MediaPipeSelfieSegmentation ;
140
144
modelConfig = handleOptions (
@@ -180,10 +184,6 @@ class BodySegmentation {
180
184
} ,
181
185
"bodySegmentation"
182
186
) ;
183
-
184
- // add constants to the instance variable
185
- this . BACKGROUND = 0 ;
186
- this . PERSON = 255 ;
187
187
}
188
188
189
189
await tf . ready ( ) ;
You can’t perform that action at this time.
0 commit comments