Skip to content

Commit

Permalink
Added debug output option per #681
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Oct 14, 2022
1 parent 9e12163 commit c7c2d73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ declare namespace Tesseract {
imageColor: boolean;
imageGrey: boolean;
imageBinary: boolean;
debug: boolean;
}
interface RecognizeOptions {
rectangle: Rectangle
Expand Down
17 changes: 12 additions & 5 deletions src/worker-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/worker-script/utils/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};

0 comments on commit c7c2d73

Please sign in to comment.