calories/javascript/camera.js

83 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-08-19 18:11:59 +02:00
import init, { init_camera_feed } from '/pkg/calories_browser.js';
await init();
init_camera_feed();
// (() => {
// // The width and height of the captured photo. We will set the
// // width to the value defined here, but the height will be
// // calculated based on the aspect ratio of the input stream.
// const width = 1080; // We will scale the photo width to this
// let height = 0; // This will be computed based on the input stream
// // |streaming| indicates whether or not we're currently streaming
// // video from the camera. Obviously, we start at false.
// let streaming = false;
// // The various HTML elements we need to configure or control. These
// // will be set by the startup() function.
// let video = null;
// let canvas = null;
// let startbutton = null;
// async function startup() {
// await init();
// video = document.getElementById("video");
// canvas = document.getElementById("canvas");
// startbutton = document.getElementById("startbutton");
// navigator.mediaDevices
// .getUserMedia({ video: true, audio: false })
// .then((stream) => {
// video.srcObject = stream;
// video.play();
// })
// .catch((err) => {
// console.error(`An error occurred: ${err}`);
// });
// video.addEventListener(
// "canplay",
// (ev) => {
// if (!streaming) {
// height = video.videoHeight / (video.videoWidth / width);
// // Firefox currently has a bug where the height can't be read from
// // the video, so we will make assumptions if this happens.
// if (isNaN(height)) {
// height = width / (4 / 3);
// }
// video.setAttribute("width", width);
// video.setAttribute("height", height);
// canvas.setAttribute("width", width);
// canvas.setAttribute("height", height);
// streaming = true;
// }
// },
// false,
// );
// startbutton.addEventListener(
// "click",
// (ev) => {
// takepicture();
// ev.preventDefault();
// },
// false,
// );
// }
// function takepicture() {
// fill_barcode();
// }
// // Set up our event listener to run the startup process
// // once loading is complete.
// // window.addEventListener("load", startup, false);
// })();