tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

OCR optical character recognition of seven segment displays

Tue Oct 08, 2013 9:39 pm

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?

User avatar
jbeale
Posts: 3471
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: OCR optical character recognition of seven segment displ

Tue Oct 08, 2013 10:13 pm

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.

User avatar
jbeale
Posts: 3471
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: OCR optical character recognition of seven segment displ

Tue Oct 08, 2013 11:18 pm

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

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: OCR optical character recognition of seven segment displ

Wed Oct 09, 2013 10:55 am

Fantastic- one of those really useful jbeale replies!
I'm off to play. Can always do some pre-processing with ImageMagick...
Thanks again.

snoopy1369
Posts: 1
Joined: Fri Jan 24, 2014 10:53 pm

Re: OCR optical character recognition of seven segment displ

Fri Jan 24, 2014 11:01 pm

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

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: OCR optical character recognition of seven segment displ

Sat May 31, 2014 8:23 am

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.

kshitij sirohi
Posts: 5
Joined: Fri Jul 10, 2015 5:45 pm

Re: OCR optical character recognition of seven segment displ

Fri Jul 10, 2015 5:51 pm

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 :)

kshitij sirohi
Posts: 5
Joined: Fri Jul 10, 2015 5:45 pm

Re: OCR optical character recognition of seven segment displ

Fri Jul 10, 2015 6:27 pm

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

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: OCR optical character recognition of seven segment displ

Fri Jul 10, 2015 9:19 pm

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....

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: OCR optical character recognition of seven segment displ

Fri Jul 10, 2015 9:38 pm

You might look at http://blog.miguelgrinberg.com/post/a-c ... spberry-pi for some help too..

kshitij sirohi
Posts: 5
Joined: Fri Jul 10, 2015 5:45 pm

Re: OCR optical character recognition of seven segment displ

Fri Jul 10, 2015 11:11 pm

thanx a lot for such a fast response. will be trying it soon and i hope it will work. :D

kshitij sirohi
Posts: 5
Joined: Fri Jul 10, 2015 5:45 pm

Re: OCR optical character recognition of seven segment displ

Sat Jul 11, 2015 5:02 pm

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?

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: OCR optical character recognition of seven segment displ

Sat Jul 11, 2015 7:20 pm

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,

kshitij sirohi
Posts: 5
Joined: Fri Jul 10, 2015 5:45 pm

Re: OCR optical character recognition of seven segment displ

Sat Jul 11, 2015 7:37 pm

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 :)

User avatar
DougieLawson
Posts: 35581
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: OCR optical character recognition of seven segment displ

Sun Jul 12, 2015 3:50 pm

sudo adduser pi dialout
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Displacedmic
Posts: 2
Joined: Sat Aug 20, 2016 5:13 am

Re: OCR optical character recognition of seven segment displ

Sat Aug 20, 2016 10:56 am

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?

User avatar
scruss
Posts: 2360
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: OCR optical character recognition of seven segment displ

Sat Aug 20, 2016 2:49 pm

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.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Displacedmic
Posts: 2
Joined: Sat Aug 20, 2016 5:13 am

Re: OCR optical character recognition of seven segment displ

Mon Aug 22, 2016 1:15 am

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

Return to “Automation, sensing and robotics”