Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support psm 0 #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion lib/tesseract.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ var Tesseract = {

// assemble tesseract command
var command = [options.binary, image, output];
if (options.psm == 0) {
command = [options.binary, image, 'stdout'];
}

if (options.l !== null) {
command.push('-l ' + options.l);
Expand All @@ -74,7 +77,7 @@ var Tesseract = {
var opts = options.env || {};

// Run the tesseract command
exec(command, opts, function(err) {
var childProcess = exec(command, opts, function(err) {
if (err) {
// Something went wrong executing the assembled command
callback(err, null);
Expand All @@ -98,15 +101,50 @@ var Tesseract = {

fs.unlink(files[0]);

if (options.psm == 0) {
data = parseOsdOutput(data);
}
callback(null, data)
});
})
}); // end exec

if (options.psm == 0) {
childProcess.stderr.pipe(fs.createWriteStream(output + '.txt'));
}

}

};

function parseOsdOutput(string) {
return string
.split('\n')
.reduce(function(obj, line) {
var result;

result = /Orientation in degrees: (\d+)/.exec(line);
if (result) {
obj.orientation = parseInt(result[1]);
return obj;
}

result = /Orientation confidence: (\d+(\.\d+))/.exec(line);
if (result) {
obj.orientationConfidence = parseFloat(result[1]);
return obj;
}

result = /Script confidence: (\d+(\.\d+))/.exec(line);
if (result) {
obj.scriptConfidence = parseFloat(result[1]);
return obj;
}

return obj;
}, {});
}

function gc() {
for (var i = Tesseract.tmpFiles.length - 1; i >= 0; i--) {
try {
Expand Down