gpt4 book ai didi

javascript - Node.js 比使用 Tesseract.Js 的浏览器 (Safari) 慢 20 倍

转载 作者:数据小太阳 更新时间:2023-10-29 05:37:45 26 4
gpt4 key购买 nike

JS 的新手和 Node.js 的新手。 在 Safari 中运行 Tesseract.js(文本识别软件:http://tesseract.projectnaptha.com)大约需要 10 秒,并立即开始输出进度。
Node (v6.9.1)(从终端或通过 Electron 运行)在开始输出到控制台之前将 CPU 运行到 100% 4 分 20 秒。然后它大约在同一时间完成。

建议采取哪些故障排除步骤?这对 Node 来说很常见吗?
我在日志中看到的唯一区别是 Safari“在缓存 eng.traineddata 中找到”清除和禁用缓存对时间的影响很小。 尝试了几个 .JPG 和 .PNG (300-600kb) 文件,结果相同 - 但 BMP (3.7MB) 给出了 17 秒的快速响应 - 然后出错并且没有完成。 (这是“下一个报价”问题吗?)

var Tesseract = require('tesseract.js');  
var image = "./images/sample.jpg";

function tesseract(){
Tesseract.recognize(image)
.progress(function(message){console.log(message)})
.then(result => console.log(result.text))
}
tesseract();

(编辑器强制将输出格式化为代码)
Node 控制台.Log

>Bash-3.2$ node JustTess.js  
*Waits 4+ min and Then*
{ status: 'loading tesseract core' }
{ status: 'loaded tesseract core' }
{ status: 'initializing tesseract', progress: 0 }
pre-main prep time:108 ms
{ status: 'initializing tesseract', progress: 1 }
{ status: 'loading eng.traineddata', progress: 0 }
{ status: 'loading eng.traineddata', progress: 1 }
{ status: 'initializing api', progress: 0 }
{ status: 'initializing api', progress: 0.3 }
{ status: 'initializing api', progress: 0.6 }
{ status: 'initializing api', progress: 1 }
{ status: 'recognizing text', progress: 0 }
{ status: 'recognizing text', progress: 0.014285714 }...

SAFARI 控制台日志

>[Log]  – {status: "loading tesseract core"}  
[Log] – {status: "loaded tesseract core"}
[Log] – {status: "initializing tesseract api"}
[Log] pre-main prep time: 115 ms (index.js, line 10)
[Log] – {status: "initialized tesseract api"}
[Log] – {status: "found in cache eng.traineddata"}
[Log] – {status: "loaded eng.traineddata"}
[Log] – {status: "initialized with language"}
[Log] – {status: "recognizing text", progress: 0}
[Log] – {status: "recognizing text", progress: 0.0142}...

带有 BMP 的 Node

bash-3.2$ node JustTess.js
*After 17 sec*
{ status: 'initializing tesseract', progress: 0 }
pre-main prep time: 118 ms
{ status: 'initializing tesseract', progress: 1 }
{ status: 'loading eng.traineddata', progress: 0 }
{ status: 'loading eng.traineddata', progress: 1 }
{ status: 'initializing api', progress: 0 }
{ status: 'initializing api', progress: 0.3 }
{ status: 'initializing api', progress: 0.6 }
Error in pixRemoveColormap: pixs must be {1,2,4,8} bpp
Error in pixGetDepth: pix not defined
Error in pixGetWpl: pix not defined
Error in pixCreateHeader: depth must be {1, 2, 4, 8, 16, 24, 32}
Error in pixCreateNoInit: pixd not made
Error in pixCreateTemplateNoInit: pixd not made
Error in pixCreateTemplate: pixd not made
Error in pixCopy: pixd not made
{ status: 'initializing api', progress: 1 }
3
3

/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_modules/tesser
act.js-core/index.js:4
function f(a){throw a;}var h=void 0,i=!0,j=null,k=!1;function aa(){return function(){}}function ba(
a){return function(){return a}}var n,Module;Module||(Module=eval("(function() { try { return Tesser
actCore || {} } catch(e) { return {} } })()"));var ca={},da;for(da in Module)Module.hasOwnProperty(
da)&&(ca[da]=Module[da]);var ea=i,fa=!ea&&i;
^
abort(3) at Error
at Error (native)
at Na (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_mod
ules/tesseract.js-core/index.js:32:26)
at ka (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_mod
ules/tesseract.js-core/index.js:507:108)
at Array.JHa (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/n
ode_modules/tesseract.js-core/index.js:402:25808)
at xd (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_mod
ules/tesseract.js-core/index.js:382:924)
at R.TesseractCore.V.Begin (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programmi
ng/GitHub/ba/node_modules/tesseract.js-core/index.js:511:288)
at DumpLiterallyEverything (/Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programmi
ng/GitHub/ba/node_modules/tesseract.js/src/common/dump.js:13:8)
at /Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_modules
/tesseract.js/src/common/worker.js:121:22
at /Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_modules
/tesseract.js/src/common/worker.js:92:9
at /Users/brent/Library/Mobile Documents/com~apple~CloudDocs/Programming/GitHub/ba/node_modules
/tesseract.js/src/node/lang.js:14:25
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

最佳答案

我无法回答这个问题;但是,其他答案并没有说明这个问题。参见 http://www.jsbenchmarks.com/?anywhichway/lookup/master/benchmark.js/例如,NodeJS 和浏览器在许多功能上有何显着差异。请注意,尽管此站点上的浏览器结果来自多个访问者,而 Node 结果来自单个服务器,但在隔离环境中的测试显示的是同一件事。

关于javascript - Node.js 比使用 Tesseract.Js 的浏览器 (Safari) 慢 20 倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40463777/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com