이재호

modify model and webcam function

...@@ -164,40 +164,43 @@ ...@@ -164,40 +164,43 @@
164 <script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"></script> 164 <script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"></script>
165 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 165 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
166 <script type="text/javascript"> 166 <script type="text/javascript">
167 - // More API functions here: 167 + // More API functions here:
168 - // https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image 168 + // https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
169 169
170 - // the link to your model provided by Teachable Machine export panel 170 + // the link to your model provided by Teachable Machine export panel
171 - const URL = "https://teachablemachine.withgoogle.com/models/ujJHV9bKh/"; 171 + const URL = "https://teachablemachine.withgoogle.com/models/ujJHV9bKh/";
172 +
173 + let model, webcam, labelContainer, maxPredictions;
172 174
173 - let model, webcam, labelContainer, maxPredictions; 175 + //predic이전 값을 기억해주는 전역변수. -999로 초기화.
176 + var last_result_predict=-999;
174 177
175 - // Load the image model and setup the webcam 178 + // Load the image model and setup the webcam
176 - async function init() { 179 + window.onload = async function init() {
177 - const modelURL = URL + "model.json"; 180 + const modelURL = URL + "model.json";
178 - const metadataURL = URL + "metadata.json"; 181 + const metadataURL = URL + "metadata.json";
179 182
180 - // load the model and metadata 183 + // load the model and metadata
181 - // Refer to tmImage.loadFromFiles() in the API to support files from a file picker 184 + // Refer to tmImage.loadFromFiles() in the API to support files from a file picker
182 - // or files from your local hard drive 185 + // or files from your local hard drive
183 - // Note: the pose library adds "tmImage" object to your window (window.tmImage) 186 + // Note: the pose library adds "tmImage" object to your window (window.tmImage)
184 - model = await tmImage.load(modelURL, metadataURL); 187 + model = await tmImage.load(modelURL, metadataURL);
185 - maxPredictions = model.getTotalClasses(); 188 + maxPredictions = model.getTotalClasses();
186 189
187 - // Convenience function to setup a webcam 190 + // Convenience function to setup a webcam
188 - const flip = true; // whether to flip the webcam 191 + const flip = true; // whether to flip the webcam
189 - webcam = new tmImage.Webcam(200, 200, flip); // width, height, flip 192 + webcam = new tmImage.Webcam(550, 550, flip); // width, height, flip
190 - await webcam.setup(); // request access to the webcam 193 + await webcam.setup(); // request access to the webcam
191 - await webcam.play(); 194 + await webcam.play();
192 - window.requestAnimationFrame(loop); 195 + window.requestAnimationFrame(loop);
193 196
194 - // append elements to the DOM 197 + // append elements to the DOM
195 - document.getElementById("webcam-container").appendChild(webcam.canvas); 198 + document.getElementById("webcam-container").appendChild(webcam.canvas);
196 - labelContainer = document.getElementById("label-container"); 199 + labelContainer = document.getElementById("label-container");
197 - for (let i = 0; i < maxPredictions; i++) { // and class labels 200 + for (let i = 0; i < maxPredictions; i++) { // and class labels
198 - labelContainer.appendChild(document.createElement("div")); 201 + labelContainer.appendChild(document.createElement("div"));
199 - }
200 } 202 }
203 + }
201 204
202 async function loop() { 205 async function loop() {
203 webcam.update(); // update the webcam frame 206 webcam.update(); // update the webcam frame
......