Merge pull request #9713 from huningxin:fix_9712

This commit is contained in:
Alexander Alekhin 2017-09-26 09:03:34 +00:00
commit e8ee284710
4 changed files with 30 additions and 20 deletions

View File

@ -189,6 +189,7 @@ if(BUILD_DOCS AND DOXYGEN_FOUND)
set(haar_cascade_files "") set(haar_cascade_files "")
set(data_harrcascades_path "${OpenCV_SOURCE_DIR}/data/haarcascades/") set(data_harrcascades_path "${OpenCV_SOURCE_DIR}/data/haarcascades/")
list(APPEND js_tutorials_assets_deps "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml") list(APPEND js_tutorials_assets_deps "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
list(APPEND js_assets "${data_harrcascades_path}/haarcascade_frontalface_default.xml" "${data_harrcascades_path}/haarcascade_eye.xml")
foreach(f ${js_assets}) foreach(f ${js_assets})
get_filename_component(fname "${f}" NAME) get_filename_component(fname "${f}" NAME)

View File

@ -77,18 +77,14 @@ tryIt.addEventListener('click', () => {
}); });
utils.loadOpenCv(() => { utils.loadOpenCv(() => {
tryIt.removeAttribute('disabled'); 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> </script>
</body> </body>
</html> </html>

View File

@ -131,16 +131,11 @@ function onVideoStopped() {
startAndStop.innerText = 'Start'; startAndStop.innerText = 'Start';
} }
let Module = {
preRun: [function() {
Module.FS_createPreloadedFile(
'/', 'haarcascade_frontalface_default.xml',
'haarcascade_frontalface_default.xml', true, false);
}],
};
utils.loadOpenCv(() => { utils.loadOpenCv(() => {
startAndStop.removeAttribute('disabled'); let faceCascadeFile = 'haarcascade_frontalface_default.xml';
utils.createFileFromUrl(faceCascadeFile, faceCascadeFile, () => {
startAndStop.removeAttribute('disabled');
});
}); });
</script> </script>
</body> </body>

View File

@ -19,6 +19,24 @@ function Utils(errorOutputId) { // eslint-disable-line no-unused-vars
node.parentNode.insertBefore(script, node); 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) { this.loadImageToCanvas = function(url, cavansId) {
let canvas = document.getElementById(cavansId); let canvas = document.getElementById(cavansId);
let ctx = canvas.getContext('2d'); let ctx = canvas.getContext('2d');