Browse Source

Added debug output option per #681

dev/v4
Balearica 3 years ago
parent
commit
c7c2d73d58
  1. 1
      src/index.d.ts
  2. 17
      src/worker-script/index.js
  3. 1
      src/worker-script/utils/dump.js

1
src/index.d.ts vendored

@ -73,6 +73,7 @@ declare namespace Tesseract { @@ -73,6 +73,7 @@ declare namespace Tesseract {
imageColor: boolean;
imageGrey: boolean;
imageBinary: boolean;
debug: boolean;
}
interface RecognizeOptions {
rectangle: Rectangle

17
src/worker-script/index.js

@ -281,11 +281,16 @@ const recognize = async ({ @@ -281,11 +281,16 @@ const recognize = async ({
optionsTess[param] = options[param];
}
}
if (Object.keys(optionsTess).length > 0) {
api.SaveParameters();
for (const prop in optionsTess) {
api.SetVariable(prop, optionsTess[prop]);
}
}
if (output.debug) {
optionsTess["debug_file"] = "/debugInternal.txt";
TessModule.FS.writeFile("/debugInternal.txt", "");
}
// If any parameters are changed here they are changed back at the end
if (Object.keys(optionsTess).length > 0) {
api.SaveParameters();
for (const prop in optionsTess) {
api.SetVariable(prop, optionsTess[prop]);
}
}
@ -345,6 +350,8 @@ const recognize = async ({ @@ -345,6 +350,8 @@ const recognize = async ({
const result = dump(TessModule, api, workingOutput, {pdfTitle, pdfTextOnly});
result.rotateRadians = rotateRadiansFinal;
if (output.debug) TessModule.FS.unlink("/debugInternal.txt");
if (Object.keys(optionsTess).length > 0) {
api.RestoreParameters();
}

1
src/worker-script/utils/dump.js

@ -219,5 +219,6 @@ module.exports = (TessModule, api, output, options) => { @@ -219,5 +219,6 @@ module.exports = (TessModule, api, output, options) => {
psm: enumToString(api.GetPageSegMode(), 'PSM'),
oem: enumToString(api.oem(), 'OEM'),
version: api.Version(),
debug: output.debug ? TessModule.FS.readFile('/debugInternal.txt', { encoding: 'utf8', flags:"a+" }) : null
};
};

Loading…
Cancel
Save