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 {
imageColor: boolean; imageColor: boolean;
imageGrey: boolean; imageGrey: boolean;
imageBinary: boolean; imageBinary: boolean;
debug: boolean;
} }
interface RecognizeOptions { interface RecognizeOptions {
rectangle: Rectangle rectangle: Rectangle

17
src/worker-script/index.js

@ -281,11 +281,16 @@ const recognize = async ({
optionsTess[param] = options[param]; optionsTess[param] = options[param];
} }
} }
if (Object.keys(optionsTess).length > 0) { }
api.SaveParameters(); if (output.debug) {
for (const prop in optionsTess) { optionsTess["debug_file"] = "/debugInternal.txt";
api.SetVariable(prop, optionsTess[prop]); 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 ({
const result = dump(TessModule, api, workingOutput, {pdfTitle, pdfTextOnly}); const result = dump(TessModule, api, workingOutput, {pdfTitle, pdfTextOnly});
result.rotateRadians = rotateRadiansFinal; result.rotateRadians = rotateRadiansFinal;
if (output.debug) TessModule.FS.unlink("/debugInternal.txt");
if (Object.keys(optionsTess).length > 0) { if (Object.keys(optionsTess).length > 0) {
api.RestoreParameters(); api.RestoreParameters();
} }

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

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

Loading…
Cancel
Save