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

10
src/worker-script/index.js

@ -356,9 +356,15 @@ const detect = async ({ payload: { image } }, res) => { @@ -356,9 +356,15 @@ const detect = async ({ payload: { image } }, res) => {
const results = new TessModule.OSResults();
if (!api.DetectOS(results)) {
api.End();
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 {
const best = results.best_result;
const oid = best.orientation_id;

Loading…
Cancel
Save