Skip to content

Commit e3600f1

Browse files
committed
version 0.0.5
1 parent 4bf76d2 commit e3600f1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Javascript BCR Library](https://github.com/syneo-tools-gmbh/Javascript-BCR-Library) 0.0.4
1+
# [Javascript BCR Library](https://github.com/syneo-tools-gmbh/Javascript-BCR-Library) 0.0.5
22
## Authors: Gaspare Ferraro, Renzo Sala, Simone Ponte, Paolo Macco
33

44
BCR Library is a javascript library, using the OCR engine Tesseract.JS, that extracts name, company name, job, address, phone numbers, email and web address out of a business card picture.

src/bcr.cleaning.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function loadAndProcess(b64, callback, progress) {
4545
}
4646

4747
// ****************************************************************************
48-
// preprocessing pipeline
48+
// Preprocessing pipeline
4949
// ****************************************************************************
5050
function pipeline(img, progress, callback) {
5151
prepareImage(img, progress, function (data) {
@@ -91,7 +91,7 @@ function pipeline(img, progress, callback) {
9191
}
9292

9393
// ****************************************************************************
94-
// image preparation pipeline
94+
// Image preparation pipeline
9595
// ****************************************************************************
9696
function prepareImage(b64image, progress, callback) {
9797

@@ -148,6 +148,7 @@ function normalizeSize(canvas) {
148148
return canvas;
149149
}
150150

151+
// TODO: Replace with OpenCV.js smart crop
151152
// ****************************************************************************
152153
// isolate card and crop
153154
// ****************************************************************************
@@ -214,9 +215,16 @@ function getPixel(data, y, x, width) {
214215
// set pixel function
215216
// ****************************************************************************
216217
function setPixel(data, y, x, width, r, g, b, a) {
218+
217219
if (typeof a === "undefined") {
218220
a = 255;
219221
}
222+
223+
r = Math.min(255, Math.max(r, 0));
224+
g = Math.min(255, Math.max(g, 0));
225+
b = Math.min(255, Math.max(b, 0));
226+
a = Math.min(255, Math.max(a, 0));
227+
220228
let baseIdx = (y * width + x) * 4;
221229
data[baseIdx] = r;
222230
data[baseIdx + 1] = g;
@@ -439,7 +447,7 @@ function boundingBox(ccs, canvas) {
439447
let BlockW = Math.floor(W / 64);
440448
let BlockH = 2;
441449

442-
let minX = 999999, minY = 999999, maxX = 0, maxY = 0;
450+
let minX = 10e9, minY = 10e9, maxX = 0, maxY = 0;
443451

444452
for (let k = 0; k < ccs.length; k++) {
445453
let cc = ccs[k];

0 commit comments

Comments
 (0)