Open wzhsunn opened 4 years ago
Can you run bash -ex build.sh
and post the output to see where the build fails. What version of emscripten are you using? Do you have it installed in the right place ($HOME/emsdk_portable
)?
Thank you for your reply. the demo.html work well .
But the examples/browser/simple.html dosen't work
56f257e7-1625-4a15-b046-8544dc405fdd:13 Uncaught ReferenceError: Module is not defined
at createOcradInstance (56f257e7-1625-4a15-b046-8544dc405fdd:13)
at 56f257e7-1625-4a15-b046-8544dc405fdd:79000
Maybe something not init well, but the ocrad.js in the origin repo work well .
what should I do ?
This is my build.sh
# Define your emscripten path. Change it you don't use emscripten portable
#PATH="$HOME/emsdk_portable:$HOME/emsdk_portable/clang/fastcomp/build_master_64/bin:$HOME/emsdk_portable/node/4.1.1_64bit/bin:$HOME/emsdk_portable/emscripten/master:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
PATH="$HOME/emsdk_portable:$HOME/emsdk_portable/fastcomp/bin:$HOME/emsdk_portable/node/12.9.1_64bit/bin:$HOME/emsdk_portable/fastcomp/emscripten:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
#EMSCRIPTEN="$HOME/emsdk_portable/emscripten/master"
EMSCRIPTEN="$HOME/emsdk_portable/fastcomp/emscripten"
# autogenerate some parts of the postcode
python src/generate.py
# compile ocrad
cd ocrad-0.25
emconfigure ./configure
emmake make
emcc -02 --memory-init-file 0 -s WASM=0 -v -s TOTAL_MEMORY=33554432 -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' -s EXPORTED_FUNCTIONS="[ '_OCRAD_set_exportfile', '_OCRAD_transform', '_OCRAD_add_filter', '_OCRAD_version', '_OCRAD_open', '_OCRAD_close', '_OCRAD_get_errno', '_OCRAD_set_image', '_OCRAD_set_image_from_file', '_OCRAD_set_utf8_format', '_OCRAD_set_threshold', '_OCRAD_scale', '_OCRAD_recognize', '_OCRAD_result_blocks', '_OCRAD_result_lines', '_OCRAD_result_chars_total', '_OCRAD_result_chars_block', '_OCRAD_result_chars_line', '_OCRAD_result_line', '_OCRAD_result_first_character']" ocradlib.o page_image_io.o page_image.o rectangle.o textpage.o bitmap.o blob.o textblock.o character_r11.o ucs.o character.o textline.o track.o rational.o profile.o mask.o feats.o common.o feats_test0.o feats_test1.o segment.o character_r12.o character_r13.o textline_r2.o arg_parser.o user_filter.o iso_8859.o -o ../ocrad.js --pre-js ../src/pre.js --post-js ../src/post.js
#-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]'
make clean
This is definitely an issue with the current (>=2015) version of emscripten. A workaround could be something like https://github.com/jedisct1/libsodium.js/commit/8f6c6a816eb608e9e18b77faacbb8e60fef119dd with a dummy definition of Module
global.
I compile ocradjs , add --closure 1
emcc -02 --memory-init-file 0 -s WASM=0 --closure 1 -v -s TOTAL_MEMORY=33554432 -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' -s EXPORTED_FUNCTIONS="[ '_OCRAD_set_exportfile', '_OCRAD_transform', '_OCRAD_add_filter', '_OCRAD_version', '_OCRAD_open', '_OCRAD_close', '_OCRAD_get_errno', '_OCRAD_set_image', '_OCRAD_set_image_from_file', '_OCRAD_set_utf8_format', '_OCRAD_set_threshold', '_OCRAD_scale', '_OCRAD_recognize', '_OCRAD_result_blocks', '_OCRAD_result_lines', '_OCRAD_result_chars_total', '_OCRAD_result_chars_block', '_OCRAD_result_chars_line', '_OCRAD_result_line', '_OCRAD_result_first_character']" ocradlib.o page_image_io.o page_image.o rectangle.o textpage.o bitmap.o blob.o textblock.o character_r11.o ucs.o character.o textline.o track.o rational.o profile.o mask.o feats.o common.o feats_test0.o feats_test1.o segment.o character_r12.o character_r13.o textline_r2.o arg_parser.o user_filter.o iso_8859.o -o ../ocrad.js --pre-js ../src/pre.js --post-js ../src/post.js
and numbers.html:
<body>
<h1>Numeric Ocrad.js Example</h1>
<script>
var Module = typeof Module !== 'undefined' ? Module : {};
function recognize_image(){
document.getElementById('transcription').innerText = "(Recognizing...)";
var text = OCRAD(document.getElementById("pic")
, {
numeric: true
}, function(text){
document.getElementById('transcription').className = "done"
document.getElementById('transcription').innerText = text;
});
}
</script>
<script src="../../ocrad.js"></script>
<div id="main">
<img id="pic" src="img/numbers.png" onclick="recognize_image()">
<div id="transcription"></div>
</div>
</body>
but the problem is as same as before :
a0c13ace-408a-49b9-ae49-00b05c4e63be:13 Uncaught ReferenceError: Module is not defined
at createOcradInstance (a0c13ace-408a-49b9-ae49-00b05c4e63be:13)
at a0c13ace-408a-49b9-ae49-00b05c4e63be:79000
Also in ocrad.js define Modue by pre.js
// The Module object: Our interface to the outside world. We import
// and export values on it. There are various ways Module can be used:
// 1. Not defined. We create it here
// 2. A function parameter, function(Module) { ..generated code.. }
// 3. pre-run appended it, var Module = {}; ..generated code..
// 4. External script tag defines var Module.
// We need to check if Module already exists (e.g. case 3 above).
// Substitution will be replaced with actual code on later stage of the build,
// this way Closure Compiler will not mangle it (e.g. case 4. above).
// Note that if you want to run closure, and also to use Module
// after the generated code, you will need to define var Module = {};
// before the code. Then that object will be used in the code, and you
// can continue to use Module afterwards as well.
var Module = typeof Module !== 'undefined' ? Module : {};
// --pre-jses are emitted after the Module integration code, so that they can
// refer to Module (if they choose; they can also define Module)
var OCRAD = (function(){
function createOcradInstance(){
// more code ...
And the performance is not very well on safari on iPhone X, recognize took 500 seconds.
Sorry, I'm out of ideas. ocrad.js is a cool hack but it's a hack. ocrad itself can only do so much (try it on the command line, it's available for all major linux distros). If you have to do the OCR within a browser, maybe try tesseract.js. If it can be a client-server app, you have a wide variety of more modern choices.
thank you very much. Could you help me with the module is not defined problem ? I try it a lot times , but it dose not work .