function init_preprocessing(input_width, display_container, sample_container, on_capture_callback, on_shadow_callback, on_calibration) {
let zodiac = true;
let video = null;
let package = null;
let thread = null
let height = 0;
let width = 0;
const FPS = 30;
let canvasFrame = null;
let context = null;
let src = null;
let background = null;
let dst = null;
let ones = null;
let zeros = null;
let disp = null;
let disp_warpped = null;
let M_raw_to_capture_to_disp = null;
let M_raw_to_capture = cv.matFromArray(2, 3, cv.CV_64FC1, [1, 0, 0, 0, 1, 0]);
let capture_res = null;
let raw_to_capture_to_disp_ratio = null;
let capture_x = 0;
let capture_y = 0;
let capture_res_percent = 1;
let capture_alpha = 0.05;
let raw_offset_x = 0;
let raw_offset_y = 0;
let raw_to_disp_ratio = null;
let M_raw_to_disp = null;
let disp_width = input_width;
let disp_height = disp_width;
let disp_offset_x = 0;
let disp_offset_y = 0;
let mode = 0;
let mode_steps = 0
let background_update_alpha = 0.05
// tracking
let tx = -1;
let ty = -1;
let ta = 0.1;
let epsilon = 200;
let countdown = 1000;
let stamp = new Date().getTime();
let allow_capture = true;
let allow_pre_capture = false;
let first = true;
function reset_state() {
tx = -1;
ty = -1;
allow_pre_capture = false;
first = true;
allow_capture = true;
}
function in_criterior(x, y) {
return (x - tx) * (x - tx) + (y - ty) * (y - ty) < epsilon;
}
$(document).ready(function() {
init(640, 480);
request_stream(assign_stream);
});
function request_stream(callback) {
navigator.mediaDevices.getUserMedia({ video: { width: { min: 640 }, height: { min: 480 } }, audio: false })
.then(function(stream) {
callback(stream);
})
.catch(function(err) {
});
};
function assign_stream(stream) {
if(thread != null) clearTimeout(thread);
video = document.getElementById("videoInput"); // video is the id of video tag
video.srcObject = stream;
video.play();
thread = setTimeout(processVideo, 0);
}
function stop_stream(){
clearTimeout(thread);
thread = null;
video.srcObject.getTracks()[0].stop();
}
function init(w, h) {
width = w;
height = h;
body = $('body');
videoElement = $('');
body.append(videoElement);
videoElement.hide();
canvasElement = $('');
body.append(canvasElement);
canvasElement.hide();
canvasFrame = document.getElementById("canvasFrame"); // canvasFrame is the id of