@@ -23,10 +23,12 @@ const imageDataFrom1Channel = (data, width, height) => {
2323  const  array  =  new  Uint8ClampedArray ( cb ) 
2424  data . forEach ( ( pixelValue ,  index )  =>  { 
2525    const  base  =  index  *  4 
26-     array [ base ]  =  pixelValue  // R 
27-     array [ base  +  1 ]  =  pixelValue  // G 
28-     array [ base  +  2 ]  =  pixelValue  // B 
29-     array [ base  +  3 ]  =  255  // A 
26+     const  r  =  g  =  b  =  pixelValue 
27+     const  a  =  255 
28+     array [ base ]  =  r 
29+     array [ base  +  1 ]  =  g 
30+     array [ base  +  2 ]  =  b 
31+     array [ base  +  3 ]  =  a 
3032  } ) 
3133  const  imageData  =  new  ImageData ( array ,  width ,  height ) 
3234  return  imageData 
@@ -48,6 +50,15 @@ const drawOutputImage = imageData => {
4850  ctx . putImageData ( imageData ,  0 ,  0 ) 
4951} 
5052
53+ const  drawBoundingBox  =  ( x ,  y ,  w ,  h )  =>  { 
54+   console . log ( '[drawBoundingBox]' ) 
55+   const  canvas  =  document . getElementById ( 'input-image-overlay' ) 
56+   ctx  =  canvas . getContext ( '2d' ) 
57+   ctx . strokeStyle  =  'red' 
58+   ctx . lineWidth  =  2 
59+   ctx . strokeRect ( x ,  y ,  w ,  h ) 
60+ } 
61+ 
5162const  onProcessImage  =  ( module ,  processImage )  =>  ( )  =>  { 
5263  console . log ( '[onProcessImage]' ) 
5364  const  {  data,  width,  height }  =  getImageData ( ) 
@@ -67,6 +78,7 @@ const onProcessImage = (module, processImage) => () => {
6778    const  imageData  =  imageDataFrom4Channels ( outImageData ,  outImageWidth ,  outImageHeight ) 
6879    drawOutputImage ( imageData ) 
6980  } 
81+   drawBoundingBox ( bbx ,  bby ,  bbw ,  bbh ) 
7082  module . _free ( addr ) 
7183} 
7284
@@ -84,4 +96,8 @@ const init = module => {
8496  const  processImage  =  wrapProcessImage ( module ) 
8597  const  processImageBtn  =  document . getElementById ( 'process-image-btn' ) 
8698  processImageBtn . addEventListener ( 'click' ,  onProcessImage ( module ,  processImage ) ) 
99+   const  inputImage  =  document . getElementById ( 'input-image' ) 
100+   const  inputImageOverlay  =  document . getElementById ( 'input-image-overlay' ) 
101+   inputImageOverlay . width  =  inputImage . width 
102+   inputImageOverlay . height  =  inputImage . height 
87103} 
0 commit comments