Skip to content

Commit

Permalink
Removed various depreciated functions, including default parameters to
Browse files Browse the repository at this point in the history
…fix #975 (#981)
  • Loading branch information
Balearica authored Dec 24, 2024
1 parent 2f2b5e3 commit 15ed597
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 72 deletions.
22 changes: 0 additions & 22 deletions src/createWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
}))
);

const loadLanguage = () => (
console.warn('`loadLanguage` is depreciated and should be removed from code (workers now come with language pre-loaded)')
);

const loadLanguageInternal = (_langs, jobId) => startJob(createJob({
id: jobId,
action: 'loadLanguage',
Expand All @@ -125,10 +121,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
},
}));

const initialize = () => (
console.warn('`initialize` is depreciated and should be removed from code (workers now come pre-initialized)')
);

const initializeInternal = (_langs, _oem, _config, jobId) => (
startJob(createJob({
id: jobId,
Expand Down Expand Up @@ -182,15 +174,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
}))
);

const getPDF = (title = 'Tesseract OCR Result', textonly = false, jobId) => {
console.log('`getPDF` function is depreciated. `recognize` option `savePDF` should be used instead.');
return startJob(createJob({
id: jobId,
action: 'getPDF',
payload: { title, textonly },
}));
};

const detect = async (image, jobId) => {
if (lstmOnlyCore) throw Error('`worker.detect` requires Legacy model, which was not loaded.');

Expand Down Expand Up @@ -224,8 +207,6 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
let d = data;
if (action === 'recognize') {
d = circularize(data);
} else if (action === 'getPDF') {
d = Array.from({ ...data, length: Object.keys(data).length });
}
promises[promiseId].resolve({ jobId, data: d });
delete promises[promiseId];
Expand All @@ -251,12 +232,9 @@ module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, confi
readText,
removeFile,
FS,
loadLanguage,
initialize,
reinitialize,
setParameters,
recognize,
getPDF,
detect,
terminate,
};
Expand Down
10 changes: 0 additions & 10 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ declare namespace Tesseract {
recognize(image: ImageLike, options?: Partial<RecognizeOptions>, output?: Partial<OutputFormats>, jobId?: string): Promise<RecognizeResult>
detect(image: ImageLike, jobId?: string): Promise<DetectResult>
terminate(jobId?: string): Promise<ConfigResult>
getPDF(title?: string, textonly?: boolean, jobId?: string):Promise<GetPDFResult>
}

interface Lang {
Expand Down Expand Up @@ -71,11 +70,6 @@ declare namespace Tesseract {
tessedit_char_blacklist: string
preserve_interword_spaces: string
user_defined_dpi: string
tessjs_create_hocr: string
tessjs_create_tsv: string
tessjs_create_box: string
tessjs_create_unlv: string
tessjs_create_osd: string
[propName: string]: any
}
interface OutputFormats {
Expand Down Expand Up @@ -108,10 +102,6 @@ declare namespace Tesseract {
jobId: string
data: Page
}
interface GetPDFResult {
jobId: string
data: number[]
}
interface DetectResult {
jobId: string
data: DetectData
Expand Down
14 changes: 0 additions & 14 deletions src/worker-script/constants/defaultParams.js

This file was deleted.

27 changes: 1 addition & 26 deletions src/worker-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const isURL = require('is-url');
const dump = require('./utils/dump');
const env = require('../utils/getEnvironment')('type');
const setImage = require('./utils/setImage');
const defaultParams = require('./constants/defaultParams');
const defaultOutput = require('./constants/defaultOutput');
const { log, setLogging } = require('../utils/log');
const PSM = require('../constants/PSM');
Expand All @@ -27,7 +26,7 @@ let TessModule;
let api = null;
let latestJob;
let adapter = {};
let params = defaultParams;
let params = {};
let loadLanguageLangsWorker;
let loadLanguageOptionsWorker;
let dataFromCache = false;
Expand Down Expand Up @@ -305,8 +304,6 @@ const initialize = async ({
res.reject('initialization failed');
}

params = defaultParams;
await setParameters({ payload: { params } });
res.progress({
workerId, status: statusText, progress: 1,
});
Expand All @@ -316,31 +313,10 @@ const initialize = async ({
}
};

const getPDFInternal = (title, textonly) => {
const pdfRenderer = new TessModule.TessPDFRenderer('tesseract-ocr', '/', textonly);
pdfRenderer.BeginDocument(title);
pdfRenderer.AddImage(api);
pdfRenderer.EndDocument();
TessModule._free(pdfRenderer);

return TessModule.FS.readFile('/tesseract-ocr.pdf');
};

const getPDF = async ({ payload: { title, textonly } }, res) => {
res.resolve(getPDFInternal(title, textonly));
};

// Combines default output with user-specified options and
// counts (1) total output formats requested and (2) outputs that require OCR
const processOutput = (output) => {
const workingOutput = JSON.parse(JSON.stringify(defaultOutput));
// Output formats were set using `setParameters` in previous versions
// These settings are copied over for compatability
if (params.tessjs_create_box === '1') workingOutput.box = true;
if (params.tessjs_create_hocr === '1') workingOutput.hocr = true;
if (params.tessjs_create_osd === '1') workingOutput.osd = true;
if (params.tessjs_create_tsv === '1') workingOutput.tsv = true;
if (params.tessjs_create_unlv === '1') workingOutput.unlv = true;

const nonRecOutputs = ['imageColor', 'imageGrey', 'imageBinary', 'layoutBlocks', 'debug'];
let recOutputCount = 0;
Expand Down Expand Up @@ -546,7 +522,6 @@ exports.dispatchHandlers = (packet, send) => {
initialize,
setParameters,
recognize,
getPDF,
detect,
terminate,
})[packet.action](packet, res)
Expand Down

0 comments on commit 15ed597

Please sign in to comment.