clean up startup function
This commit is contained in:
parent
0d09bb5e96
commit
2b3e939c12
|
|
@ -820,78 +820,36 @@
|
|||
|
||||
objects_last = objects_this;
|
||||
|
||||
let contoursColor = new cv.Scalar(0, 0, 255,255);
|
||||
|
||||
cv.drawContours(src, contours, -1, contoursColor, 1 );
|
||||
|
||||
cv.imshow("canvas-draw", src);
|
||||
cv.imshow("canvas-draw", draw);
|
||||
|
||||
// schedule the next one.
|
||||
let delay = 1000/FPS - (Date.now() - begin);
|
||||
setTimeout(processVideo, delay);
|
||||
//video.requestVideoFrameCallback(processVideo);
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.log(cv.exceptionFromPtr(err));
|
||||
contours.delete();
|
||||
hierarchy.delete();
|
||||
cap.delete();
|
||||
}
|
||||
};
|
||||
// schedule the first one.
|
||||
setTimeout(processVideo, 0);
|
||||
setTimeout(processVideo, 0);
|
||||
//video.requestVideoFrameCallback(processVideo);
|
||||
};
|
||||
// init video switching get IDs of video inputs
|
||||
|
||||
var deviceIDs = [];
|
||||
|
||||
navigator.mediaDevices
|
||||
.enumerateDevices()
|
||||
.then((devices) => {
|
||||
devices.forEach((device) => {
|
||||
if (device.kind=="videoinput"){
|
||||
deviceIDs.push(device.deviceId);
|
||||
}
|
||||
console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`${err.name}: ${err.message}`);
|
||||
});
|
||||
|
||||
// toggle between cameras
|
||||
|
||||
var device_index = 0;
|
||||
|
||||
function toggle_cam(){
|
||||
device_index += 1
|
||||
if (device_index>=deviceIDs.length){
|
||||
device_index=0
|
||||
};
|
||||
|
||||
if (navigator.mediaDevices.getUserMedia) {
|
||||
navigator.mediaDevices.getUserMedia({ video: {
|
||||
deviceId: deviceIDs[device_index],
|
||||
}, })
|
||||
.then(function (stream) {
|
||||
video.srcObject = stream;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log("Something went wrong!");
|
||||
});
|
||||
}
|
||||
};
|
||||
let streaming = false;
|
||||
|
||||
function startup() {
|
||||
output = document.getElementById("output");
|
||||
video = document.getElementById("video");
|
||||
canvas = document.getElementById("canvas-temp");
|
||||
|
||||
canvas_draw = document.getElementById("canvas-draw");
|
||||
photo = document.getElementById("photo");
|
||||
startButton = document.getElementById("start-button");
|
||||
|
||||
navigator.mediaDevices
|
||||
.getUserMedia({ video: {width: { ideal: 99999} , height: { ideal: 99999 }}, audio: false })
|
||||
.getUserMedia(microscope_setup.video_prefs)
|
||||
.then((stream) => {
|
||||
video.srcObject = stream;
|
||||
video.play();
|
||||
|
|
@ -912,7 +870,6 @@
|
|||
|
||||
photo.style.aspectRatio = video_aspect;
|
||||
|
||||
canvas.style.aspectRatio = video_aspect;
|
||||
|
||||
canvas_draw.style.aspectRatio = video_aspect;
|
||||
canvas_draw.height = canvas_draw.height*5;
|
||||
|
|
@ -924,8 +881,6 @@
|
|||
false,
|
||||
);
|
||||
}
|
||||
window.addEventListener("load", startup, false);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in a new issue