scribe.js-ocr 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scribe.js +36 -28
package/package.json
CHANGED
package/scribe.js
CHANGED
|
@@ -98,10 +98,14 @@ const extractText = async (files, langs = ['eng'], outputFormat = 'txt', options
|
|
|
98
98
|
* @public
|
|
99
99
|
*/
|
|
100
100
|
async function writeDebugImages(ctx, compDebugArrArr, filePath) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
if (typeof process === 'undefined') {
|
|
102
|
+
throw new Error('This function is only available in Node.js.');
|
|
103
|
+
} else {
|
|
104
|
+
await drawDebugImages({ ctx, compDebugArrArr, context: 'node' });
|
|
105
|
+
const buffer0 = ctx.canvas.toBuffer('image/png');
|
|
106
|
+
const fs = await import('fs');
|
|
107
|
+
fs.writeFileSync(filePath, buffer0);
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
/**
|
|
@@ -111,39 +115,43 @@ async function writeDebugImages(ctx, compDebugArrArr, filePath) {
|
|
|
111
115
|
* @returns
|
|
112
116
|
*/
|
|
113
117
|
async function dumpDebugImages(dir) {
|
|
114
|
-
if (typeof process === 'undefined')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
if (typeof process === 'undefined') {
|
|
119
|
+
throw new Error('This function is only available in Node.js.');
|
|
120
|
+
} else {
|
|
121
|
+
if (!DebugData.debugImg.Combined || DebugData.debugImg.Combined.length === 0) {
|
|
122
|
+
console.log('No debug images to dump.');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
120
125
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
const { createCanvas } = await import('canvas');
|
|
127
|
+
const canvasAlt = createCanvas(200, 200);
|
|
128
|
+
const ctxDebug = canvasAlt.getContext('2d');
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
for (const [name, imgArr] of Object.entries(DebugData.debugImg)) {
|
|
131
|
+
if (!imgArr || imgArr.length === 0) continue;
|
|
132
|
+
for (let i = 0; i < imgArr.length; i++) {
|
|
133
|
+
const filePath = `${dir}/${name}_${i}.png`;
|
|
134
|
+
await writeDebugImages(ctxDebug, [imgArr[i]], filePath);
|
|
135
|
+
}
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
async function dumpHOCR(dir) {
|
|
135
|
-
if (typeof process === 'undefined')
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
if (typeof process === 'undefined') {
|
|
142
|
+
throw new Error('This function is only available in Node.js.');
|
|
143
|
+
} else {
|
|
144
|
+
const activeCurrent = ocrAll.active;
|
|
145
|
+
|
|
146
|
+
const fs = await import('fs');
|
|
147
|
+
for (const [name, pages] of Object.entries(ocrAll)) {
|
|
148
|
+
ocrAll.active = pages;
|
|
149
|
+
const hocrStr = await exportData('hocr');
|
|
150
|
+
fs.writeFileSync(`${dir}/${name}.hocr`, hocrStr);
|
|
151
|
+
}
|
|
138
152
|
|
|
139
|
-
|
|
140
|
-
for (const [name, pages] of Object.entries(ocrAll)) {
|
|
141
|
-
ocrAll.active = pages;
|
|
142
|
-
const hocrStr = await exportData('hocr');
|
|
143
|
-
fs.writeFileSync(`${dir}/${name}.hocr`, hocrStr);
|
|
153
|
+
ocrAll.active = activeCurrent;
|
|
144
154
|
}
|
|
145
|
-
|
|
146
|
-
ocrAll.active = activeCurrent;
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
class data {
|