Page 1 of 1

OCR optical character recognition of seven segment displays

Posted: Tue Oct 08, 2013 9:39 pm
by tenochtitlanuk
The representation of number outputs on displays via 7 bars SHOULD be easy to recognise as numbers. This allows interfacing all sorts of existing instrumentation, including for instance bathroom weighing scales; electricity meters; etc.
I have previously written my own routines to detect the bars & decode- see elsewhere on this forum. Written in high-level code they are too slow for many purposes.
I would LIKE to use OCR. The usual suggestion is 'Tesseract', but this seems to have great difficulty even after pre-processing images to 'heal over' the gaps between bars- it expects contiguous figures. No-one on the Tesseract forums seems to have been very successful training it for this purpose.
There is software called 'SSOCR' ( http://www.unix-ag.uni-kl.de/~auerswal/ssocr/ ) which is written specifically to detect 7-seg images. It is in C.
Can any C-expert see if it can be compiled to run on Pi? Or has anyone else had any success in this kind of thing?

Re: OCR optical character recognition of seven segment displ

Posted: Tue Oct 08, 2013 10:13 pm
by jbeale
tenochtitlanuk wrote:Can any C-expert see if it can be compiled to run on Pi?
Not claiming to be an expert, but it works on the Pi. Compiling the ssocr code requires the X11 and Imlib dev libraries, so you have to install those if you don't have them. Here's what I did:

Code: Select all

sudo apt-get install libx11-dev
sudo apt-get install libimlib2-dev
wget http://www.unix-ag.uni-kl.de/~auerswal/ssocr/ssocr-2.14.1.tar.bz2
bzip2 -d ssocr-2.14.1.tar.bz2
tar xvf ssocr-2.14.1.tar
cd ssocr-2.14.1/
make
That should compile and give you the 'ssocr' executable file. To test that it works, download the sample image and give it a try:

Code: Select all

wget http://www.unix-ag.uni-kl.de/~auerswal/ssocr/six_digits.png
./ssocr -T six_digits.png
431432
Image

If you want to install this program you can type

Code: Select all

sudo make install
which puts the binary into /usr/local/bin/ssocr and also gives you a man page.

Re: OCR optical character recognition of seven segment displ

Posted: Tue Oct 08, 2013 11:18 pm
by jbeale
By the way, for real life images you will probably have to make some adjustments. I just took a photo of a multimeter with my cell phone to test it. It did work, but I first had to scale the image down very small (in this case 100 x 40 pixels) before it would recognize all the digits. I think with too many pixels it gets confused by noise and background texture. I also had to set the level threshold manually (-t 35). Also I'm not sure if it can recognize decimal points, at least it did not in this case. I'm actually pretty impressed, this was a wide-angle lens fairly close and tilted, so each of the digits have a different perspective slant, but it worked anyway.

Image

Code: Select all

[email protected]:~/$ ssocr -t 35 -d -1 dmm2.jpg
4973

Re: OCR optical character recognition of seven segment displ

Posted: Wed Oct 09, 2013 10:55 am
by tenochtitlanuk
Fantastic- one of those really useful jbeale replies!
I'm off to play. Can always do some pre-processing with ImageMagick...
Thanks again.

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jan 24, 2014 11:01 pm
by snoopy1369
Hi jbeale,

great hint, exactly what I was looking for.
I was wondering if you also have to push a physical button a few times before your 7 segment display shows the value you are interested in?
If so - did you find a solution for automatically pushing the button by a kind of electric motor or sonething?
in my case I am dealing with a heating meter.

kind regards,
Stefan

Re: OCR optical character recognition of seven segment displ

Posted: Sat May 31, 2014 8:23 am
by tenochtitlanuk
Most such scales DO require a button push, rather than giving a continuous display.
For such things I have used servos to press a button ( gives you complete electrical isolation- a GOOD idea if you are doubtful) , but if you can get at the two button contacts you can check if it's a 'pull down to earth' or similar simple logic signal, then use an opto-isolator, MOSFET or w.h.y. in parallel.

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jul 10, 2015 5:51 pm
by kshitij sirohi
i have installed and successfully compiled and the software is running to give the output for 6 digits but if the digits are less, like 4 it prints a message "found only 4 out of 6 digits". i am beginner and in a need of urgent help . please tell me what modifications i need to make so as to change the number of digits to be recognized. awaiting your help. thank you :)

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jul 10, 2015 6:27 pm
by kshitij sirohi
also please help me on how to send these digits extracted via serial communication. i want to send this data using bluetooth so please help me out. need an urgent help. thank you

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jul 10, 2015 9:19 pm
by tenochtitlanuk
For 4 digits try ssocr -d 4

Usage: ssocr [OPTION]... [COMMAND]... IMAGE
Options: -d, --number-digits=# number of digits in image (-1 for auto)

To send to a device/file I'd expect to 'pipe' it to whatever the Bluetooth device is seen as by Linux-----
eg ssocr -d 4 > /dev/ttyUSB1 or ssocr d 4 > /dev/tty0

As a test try ssocr > file.txt and see if the result is saved as a fille- Linux sees devices and files as interchangeably equivalent.
Sorry don't have access to my pis at present ( on holiday!) to test....

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jul 10, 2015 9:38 pm
by tenochtitlanuk
You might look at http://blog.miguelgrinberg.com/post/a-c ... spberry-pi for some help too..

Re: OCR optical character recognition of seven segment displ

Posted: Fri Jul 10, 2015 11:11 pm
by kshitij sirohi
thanx a lot for such a fast response. will be trying it soon and i hope it will work. :D

Re: OCR optical character recognition of seven segment displ

Posted: Sat Jul 11, 2015 5:02 pm
by kshitij sirohi
the file is successfully saved with the result as you said. :D but when i use this copmmand , i get the following message.
[email protected] ~/ssocr-2.14.1 $ ssocr -t 35 -d -1 13.jpg > /dev/tty0
bash: /dev/tty0: Permission denied

then i tried using sudo, then also i got the same

[email protected] ~/ssocr-2.14.1 $ sudo ssocr -t 35 -d -1 13.jpg > /dev/ttyUSB1
bash: /dev/ttyUSB1: Permission denied


whats wrong i am doing here?

Re: OCR optical character recognition of seven segment displ

Posted: Sat Jul 11, 2015 7:20 pm
by tenochtitlanuk
I'm still away from any Pi to try.
Google 'Raspberry Pi serial port' for lots of possible help. Try http://elinux.org/RPi_Serial_Connection .
I wonder if the port is the one whose name you are using or some other name??
I think you may have to be a member of the dialout group- I get lost here too!
Best wishes,

Re: OCR optical character recognition of seven segment displ

Posted: Sat Jul 11, 2015 7:37 pm
by kshitij sirohi
i have already gone through the bluetooth link you gave and this serial one too. i connected arduino and it is reading the data sent via uart during the boot. but in that tutorial nothing about the real time data sending is given. and also i am having an empty boot directory folder, i guess i am close but due to some silly thing i am nt able to proceed. really dont know what to do.
thank you for your support :)

Re: OCR optical character recognition of seven segment displ

Posted: Sun Jul 12, 2015 3:50 pm
by DougieLawson
sudo adduser pi dialout

Re: OCR optical character recognition of seven segment displ

Posted: Sat Aug 20, 2016 10:56 am
by Displacedmic
Hello all,
First time posting, new to Raspberry!
This thread is very exciting to me as it's exactly what I want to do with my device. I am however having some trouble installing ssocr.

I have the proper libraries installed but when I try and make and compile the executable I get an error:

[email protected]:~/Downloads/ssocr-2.14.1 $ make
cc ssocr.o imgproc.o help.o -L/usr/lib/arm-linux-gnueabihf -lImlib2 -o ssocr
/usr/bin/ld: imgproc.o: undefined reference to symbol '[email protected]@GLIBC_2.4'
//lib/arm-linux-gnueabihf/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'ssocr' failed
make: *** [ssocr] Error 1

Not sure what that means?

Re: OCR optical character recognition of seven segment displ

Posted: Sat Aug 20, 2016 2:49 pm
by scruss
Maybe best to install from the latest version on github:

Code: Select all

sudo apt install build-essential libx11-dev libimlib2-dev git
git clone https://github.com/auerswal/ssocr.git
cd ssocr
make
This worked for me.

Re: OCR optical character recognition of seven segment displ

Posted: Mon Aug 22, 2016 1:15 am
by Displacedmic
scruss wrote:Maybe best to install from the latest version on github:

This worked for me.
right on, thank you! installed fine. playing with it now