Skip to content

Instantly share code, notes, and snippets.

@AlexeyGy
Created December 6, 2020 13:38
Show Gist options
  • Save AlexeyGy/7ee081add486526776dfe10ab451b4d9 to your computer and use it in GitHub Desktop.
Save AlexeyGy/7ee081add486526776dfe10ab451b4d9 to your computer and use it in GitHub Desktop.
function take_snapshot() {
Webcam.snap(function (data_uri) {
// snap complete, image data is in 'data_uri' see https://github.com/jhuckaby/webcamjs/blob/master/DOCS.md
Webcam.upload(
data_uri,
"https://raspberrypi:5000/upload",
function (response_code, response_data) {
if (response_code === 200) {
var parsed_response_data = JSON.parse(response_data);
clearCanvas();
parsed_response_data.forEach((detection) => {
drawRect(...detection);
});
}
}
);
});
}
function drawRect(xmin, ymin, xmax, ymax) {
ctx.beginPath();
ctx.lineWidth = 5;
ctx.rect(xmin, ymin, xmax - xmin, ymax - ymin);
ctx.stroke();
}
function clearCanvas() {
ctx.clearRect(-100, -100, 10000, 10000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment