Browse Source

Edited detect to return null when detection fails rather than throwing error per #526

dev/v4
Balearica 2 years ago
parent
commit
8fb04f4593
  1. 10
      src/index.d.ts
  2. 10
      src/worker-script/index.js

10
src/index.d.ts vendored

@ -74,11 +74,11 @@ declare namespace Tesseract {
data: DetectData data: DetectData
} }
interface DetectData { interface DetectData {
tesseract_script_id: number tesseract_script_id: number | null
script: string script: string | null
script_confidence: number script_confidence: number | null
orientation_degrees: number orientation_degrees: number | null
orientation_confidence: number orientation_confidence: number | null
} }
interface Rectangle { interface Rectangle {
left: number left: number

10
src/worker-script/index.js

@ -356,9 +356,15 @@ const detect = async ({ payload: { image } }, res) => {
const results = new TessModule.OSResults(); const results = new TessModule.OSResults();
if (!api.DetectOS(results)) { if (!api.DetectOS(results)) {
api.End();
TessModule._free(ptr); TessModule._free(ptr);
res.reject('Failed to detect OS');
res.resolve({
tesseract_script_id: null,
script: null,
script_confidence: null,
orientation_degrees: null,
orientation_confidence: null,
});
} else { } else {
const best = results.best_result; const best = results.best_result;
const oid = best.orientation_id; const oid = best.orientation_id;

Loading…
Cancel
Save