Commit 3ee60f18 authored by Avnerus's avatar Avnerus

now better

parent 4b3b93b1
......@@ -34,9 +34,17 @@ window.onload = async () => {
}
function step(timestamp) {
async function step(timestamp) {
if (timestamp - Render.lastDraw >= Render.intervalSec * 1000) {
Renderer.loop(elements);
try {
await Camera.snap(elements.camera, elements.film);
let boxes = await Vision.tagImage(elements.film);
Renderer.drawBoxes(boxes, elements.boxesElement);
}
catch (err) {
console.error("Error! ", err);
}
Render.lastDraw = timestamp;
}
window.requestAnimationFrame(step);
......
import {Render} from './state'
import * as Camera from './webcam'
import * as Vision from './vision'
import * as Forms from './forms'
export function drawBoxes(boxes, element) {
element.innerHTML = "";
for (let box of boxes) {
//console.log("Draw", box);
let div = document.createElement('div');
div.style.position = "absolute";
div.style.left = box.left + "px";
div.style.top = box.top + "px";
div.style.height = (box.bottom - box.top) + "px";
div.style.width = (box.right - box.left) + "px";
div.classList.add("tag-box");
element.appendChild(div);
export async function loop(elements) {
try {
await Camera.snap(elements.camera, elements.film);
// Post to server
/*
film.toBlob((blob) => {
Forms.postImageBlob(blob, "/image/save", "image");
})*/
let boxes = await Vision.tagImage(elements.film);
//console.log(boxes);
Vision.drawBoxes(boxes, elements.boxesElement);
}
catch (err) {
console.error("Error snapping image!", err.message);
}
let titleDiv = document.createElement('div');
titleDiv.classList.add("tag-title");
titleDiv.innerHTML = box.className + " " + box.classProb.toFixed(2);
div.appendChild(titleDiv);
}
}
......@@ -7,3 +7,4 @@ export const Vision = {};
export const Webcam = {};
export const Render = {};
......@@ -20,22 +20,3 @@ export async function tagImage(canvas) {
return boxes;
}
export function drawBoxes(boxes, element) {
element.innerHTML = "";
for (let box of boxes) {
//console.log("Draw", box);
let div = document.createElement('div');
div.style.position = "absolute";
div.style.left = box.left + "px";
div.style.top = box.top + "px";
div.style.height = (box.bottom - box.top) + "px";
div.style.width = (box.right - box.left) + "px";
div.classList.add("tag-box");
element.appendChild(div);
let titleDiv = document.createElement('div');
titleDiv.classList.add("tag-title");
titleDiv.innerHTML = box.className + " " + box.classProb.toFixed(2);
div.appendChild(titleDiv);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment