These last weeks in Wentook, my new venture in IOT, we are devoting much time to R&D. We are thinking about a possible product that is able to read a license plate from a webcam. This can be useful for instance in garages.

To start we investigated on OCR command line. We focused on two options: Tesseract a Google Project and Gocr.

An example with Tesseract:

apt-get install tesseract-ocr

We call this image test.png

Test image

Run the following command in the directory where we saved the image:

tesseract test.png test

We’ll see how a document called test.txt is created, to view simply:

cat test.txt

It works! Okay now the next step is to create a program that captures an image from a Webcam and kick us the result. We are working NodeJS, so we use this knowledge to make a test area.

You can download the code from the git page:

git clone https://github.com/monchopena/myocr.git

We use as a framework Express JS and for websocket communication Socket.IO.

We’ll highlight the most important files.

File views/index.ejs.

In line 118 we load the library socket.io

... script src="javascripts/socket.io.js" ...

From line 121 we call to socket (NOTE: change the URL according to your needs) and listen to the result that the server will send us.

var socket = io.connect('http://192.168.1.130:3000');
    	
    	socket.on('from_server', function (data) {
    		console.log(data);
            $("#reader").html(data);
        });

In line 87 we have the “captureImage” function which is activated by pressing the “Camera button”, the image is sent to the server on line 106 with “socket.emit”.

 function captureImage() {
...
socket.emit('from_client', dataURL);

Now let see the File Server.

In line 36 we listen the web and websocket

var io = require('socket.io').listen(app.listen(app.get('port')));

From line 40 we wait for the client to send us a picture. First we store it and then run the OCR command in line 51.

var cmd = 'gocr public/images/test.png -o public/images/ocr.txt';

Finally we emit the result in line 64:

socket.emit('from_server', data);

This is my WebCAM:

MyOCR WebCAM

Here is a screenshot:

MyOCR Screenshot

Connecting it to an Arduino and Raspberry PI … Can you think of any ideas?