Skip to content

Instantly share code, notes, and snippets.

Last active Oct 27, 2020
What would you like to do?
Minimal usage of OpenCV.js with a single HTML file.
<!DOCTYPE html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello OpenCV.js</title>
<input type="file" id="input" name="file" />
<canvas id="output"></canvas>
<script src=""></script>
const image = new Image();
const input = document.getElementById('input');
input.addEventListener('change', (e) => {
image.src = URL.createObjectURL([0]);
}, false);
image.onload = function() {
const src = cv.imread(image);
const dst = new cv.Mat();
cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY, 0);
cv.imshow('output', dst);
src.delete(); dst.delete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment