-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocr.js
42 lines (31 loc) · 856 Bytes
/
ocr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var canvas;
var captureWidth = 640;
var captureHeight = 480;
function ocrSetup() {
canvas = createCanvas(captureWidth, captureHeight);
canvas.position(70,60);
capture = createCapture(VIDEO);
capture.size(captureWidth, captureHeight);
capture.hide();
// ocrButton = createButton('Capture text');
// ocrButton.mousePressed(saveScreen);
}
function draw() {
// for saving OCR pic
image(capture, 0, 0);
}
function saveScreen(lines) {
var baseline = 0;
// var lineHeight = 60;
var lineHeight = 50;
var cropHeight = lines * lineHeight;
var yCoord = captureHeight - cropHeight - baseline;
var cropped = canvas.get(15,yCoord,615,cropHeight);
var filename = Date.now() + '.jpg';
// save(canvas, filename);
save(cropped, filename);
sendPic(filename);
}
function sendPic(filename) {
socket.emit('runOCR', filename);
}