Page 312 - MDP2020-1
P. 312

|    인천전자마이스터고등학교  ·············································································································
            306



                            //  append  elements  to  the  DOM
                            document.getElementById("webcam-container").appendChild(webcam.canvas);
                            labelContainer  =  document.getElementById("label-container");

                            for  (let  i  =  0;  i  <  maxPredictions;  i++)  {  //  and  class  labels
                                    labelContainer.appendChild(document.createElement("div"));
                            }
                    }



                    async  function  loop()  {
                            webcam.update();  //  update  the  webcam  frame
                            await  predict();
                            window.requestAnimationFrame(loop);
                    }



                    //  run  the  webcam  image  through  the  image  model
                    async  function  predict()  {
                            //  predict  can  take  in  an  image,  video  or  canvas  html  element

                            const  prediction  =  await  model.predict(webcam.canvas);
                            for  (let  i  =  0;  i  <  maxPredictions;  i++)  {
                                    const  classPrediction  =
                                            prediction[i].className  +  ":  "  +  prediction[i].probability.toFixed(2);
                                    labelContainer.childNodes[i].innerHTML  =  classPrediction;
                            }

                    }
            </script>
   307   308   309   310   311   312   313   314   315   316   317