mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Improve cascade file loading and error handling for js tutorials
This commit is contained in:
parent
f57106b00a
commit
ea2c13c91e
@ -77,18 +77,14 @@ tryIt.addEventListener('click', () => {
|
||||
});
|
||||
|
||||
utils.loadOpenCv(() => {
|
||||
let eyeCascadeFile = 'haarcascade_eye.xml';
|
||||
utils.createFileFromUrl(eyeCascadeFile, eyeCascadeFile, () => {
|
||||
let faceCascadeFile = 'haarcascade_frontalface_default.xml';
|
||||
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
|
||||
tryIt.removeAttribute('disabled');
|
||||
});
|
||||
});
|
||||
});
|
||||
let Module = {
|
||||
preRun: [function() {
|
||||
Module.FS_createPreloadedFile('/', 'haarcascade_eye.xml',
|
||||
'haarcascade_eye.xml', true, false);
|
||||
let frontalfaceXML = 'haarcascade_frontalface_default.xml';
|
||||
let frontalfaceDefaultXML = 'haarcascade_frontalface_default.xml';
|
||||
Module.FS_createPreloadedFile('/', frontalfaceXML,
|
||||
frontalfaceDefaultXML, true, false);
|
||||
}],
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -131,16 +131,11 @@ function onVideoStopped() {
|
||||
startAndStop.innerText = 'Start';
|
||||
}
|
||||
|
||||
let Module = {
|
||||
preRun: [function() {
|
||||
Module.FS_createPreloadedFile(
|
||||
'/', 'haarcascade_frontalface_default.xml',
|
||||
'haarcascade_frontalface_default.xml', true, false);
|
||||
}],
|
||||
};
|
||||
|
||||
utils.loadOpenCv(() => {
|
||||
let faceCascadeFile = 'haarcascade_frontalface_default.xml';
|
||||
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
|
||||
startAndStop.removeAttribute('disabled');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
@ -19,6 +19,24 @@ function Utils(errorOutputId) { // eslint-disable-line no-unused-vars
|
||||
node.parentNode.insertBefore(script, node);
|
||||
};
|
||||
|
||||
this.createFileFromUrl = function(path, url, callback) {
|
||||
let request = new XMLHttpRequest();
|
||||
request.open('GET', url, true);
|
||||
request.responseType = 'arraybuffer';
|
||||
request.onload = function(ev) {
|
||||
if (request.readyState === 4) {
|
||||
if (request.status === 200) {
|
||||
let data = new Uint8Array(request.response);
|
||||
cv.FS_createDataFile('/', path, data, true, false, false);
|
||||
callback();
|
||||
} else {
|
||||
self.printError('Failed to load ' + url + ' status: ' + request.status);
|
||||
}
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
};
|
||||
|
||||
this.loadImageToCanvas = function(url, cavansId) {
|
||||
let canvas = document.getElementById(cavansId);
|
||||
let ctx = canvas.getContext('2d');
|
||||
|
Loading…
Reference in New Issue
Block a user