Skip to content

Commit

Permalink
Added street names.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBone committed Jul 22, 2018
1 parent a4ef1ef commit 235b86c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions scraper.js
Expand Up @@ -87,15 +87,15 @@ async function parseImage(image) {
// Grap a section of the image (this minimises memory usage and upscale it (this improves
// the OCR results).

jimpImage.crop(0, sectionY, image.width, sectionHeight).scale(7.0);
jimpImage.crop(0, sectionY, image.width, sectionHeight).scale(6.0, jimp.RESIZE_BEZIER);
let imageBuffer = await (new Promise((resolve, reject) => jimpImage.getBuffer(jimp.MIME_PNG, (error, buffer) => resolve(buffer))));

// Perform OCR on the image.

memoryUsage = process.memoryUsage();
console.log(` Memory Usage After Images: rss: ${Math.round(memoryUsage.rss / (1024 * 1024))} MB, heapTotal: ${Math.round(memoryUsage.heapTotal / (1024 * 1024))} MB, heapUsed: ${Math.round(memoryUsage.heapUsed / (1024 * 1024))} MB, external: ${Math.round(memoryUsage.external / (1024 * 1024))} MB`);
let result = await new Promise((resolve, reject) => {
tesseract.recognize(imageBuffer).then(function(result) {
tesseract.recognize(imageBuffer, { user_words_file: "streetnames.txt" }).then(function(result) {
resolve(result);
})
});
Expand All @@ -110,9 +110,16 @@ async function parseImage(image) {

// Analyse the resulting text.

if (result.blocks && result.blocks.length)
for (let word of result.blocks[0].paragraphs[0].lines[0].words)
if (result.blocks && result.blocks.length) {
for (let word of result.blocks[0].paragraphs[0].lines[0].words) {
console.log(` ${word.text} (confidence: ${Math.round(word.confidence)}, choices: ${word.choices.length}, x0: ${word.bbox.x0})`);
if (word.choices.length >= 2) {
for (let choice of word.choices) {
console.log(` Choice: ${choice.text} (confidence: ${Math.round(choice.confidence)})`);
}
}
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions streetnames.txt
@@ -0,0 +1,9 @@
Prospect
Carter
Churcher
Fitzroy
Main
North
Prospect
Robe
Thorngate

0 comments on commit 235b86c

Please sign in to comment.