11/********************************************************************
2- * Demo created by Jason Mayes 2020.
2+ * Real-Time-Person-Removal Created by Jason Mayes 2020.
33 *
44 * Get latest code on my Github:
55 * https://github.com/jasonmayes/Real-Time-Person-Removal
@@ -34,15 +34,18 @@ const segmentationProperties = {
3434} ;
3535
3636
37- // Must be even. The size of square we wish to search.
37+ // Must be even. The size of square we wish to search for body parts.
38+ // This is the smallest area that will render/not render depending on
39+ // if a body part is found in that square.
3840const SEARCH_RADIUS = 300 ;
3941const SEARCH_OFFSET = SEARCH_RADIUS / 2 ;
40- // Should be smaller than search_radius. Effects overlap in search space
41- // to clean up body overspill for things that were not classified as
42- // body but infact were.
42+
43+ // RESOLUTION_MIN should be smaller than SEARCH RADIUS. About 10x smaller seems to
44+ // work well. Effects overlap in search space to clean up body overspill for things
45+ // that were not classified as body but infact were.
4346const RESOLUTION_MIN = 20 ;
4447
45- // A function to render returned segmentation data to a given canvas context.
48+ // Render returned segmentation data to a given canvas context.
4649function processSegmentation ( canvas , segmentation ) {
4750 var ctx = canvas . getContext ( '2d' ) ;
4851
@@ -89,13 +92,13 @@ function processSegmentation(canvas, segmentation) {
8992 }
9093 }
9194
92-
9395 // Update patch if patch was clean.
9496 if ( ! foundBodyPartNearby ) {
9597 for ( let i = xMin ; i < xMax ; i ++ ) {
9698 for ( let j = yMin ; j < yMax ; j ++ ) {
9799 // Convert xy co-ords to array offset.
98100 let offset = j * canvas . width + i ;
101+
99102 data [ offset * 4 ] = dataL [ offset * 4 ] ;
100103 data [ offset * 4 + 1 ] = dataL [ offset * 4 + 1 ] ;
101104 data [ offset * 4 + 2 ] = dataL [ offset * 4 + 2 ] ;
@@ -108,6 +111,7 @@ function processSegmentation(canvas, segmentation) {
108111 for ( let j = yMin ; j < yMax ; j ++ ) {
109112 // Convert xy co-ords to array offset.
110113 let offset = j * canvas . width + i ;
114+
111115 data [ offset * 4 ] = 255 ;
112116 data [ offset * 4 + 1 ] = 0 ;
113117 data [ offset * 4 + 2 ] = 0 ;
@@ -119,7 +123,6 @@ function processSegmentation(canvas, segmentation) {
119123
120124 }
121125 }
122-
123126 ctx . putImageData ( imageData , 0 , 0 ) ;
124127}
125128
@@ -222,4 +225,4 @@ if (hasGetUserMedia()) {
222225 enableWebcamButton . addEventListener ( 'click' , enableCam ) ;
223226} else {
224227 console . warn ( 'getUserMedia() is not supported by your browser' ) ;
225- }
228+ }
0 commit comments