GithubHelp home page GithubHelp logo

skaringa / emeocv Goto Github PK

View Code? Open in Web Editor NEW
166.0 20.0 74.0 70 KB

Read and recognize the counter of an electricity meter with OpenCV

License: GNU General Public License v3.0

C++ 77.74% Makefile 1.92% Shell 2.22% Perl 11.81% HTML 6.31%

emeocv's Introduction

emeocv

Read and recognize the counter of an electricity meter with OpenCV.

OpenCV for the electricity meter

Prerequisites

  • g++, make
  • OpenCV 2, 3, 4 (Debian/Ubuntu/Raspbian: apt-get install libopencv-dev) - developed with OpenCV 2.3.1 and later ported to OpenCV 3.2.0 and 4.2.0
  • RRDtool (apt-get install rrdtool librrd-dev)
  • log4cpp (apt-get install liblog4cpp5-dev)

Build

cd emeocv
make

Usage

emeocv [-i <dir>|-c <cam>] [-l|-t|-a|-w|-o <dir>] [-s <delay>] [-v <level>]

Image input:
    -i <image directory> : read image files (png) from directory.
    -c <camera number> : read images from camera.

Operation:
    -a : adjust camera.
    -o <directory> : capture images into directory.
    -l : learn OCR.
    -t : test OCR.
    -w : write OCR data to RR database. This is the normal working mode.

Options:
    -s <n> : Sleep n milliseconds after processing of each image (default=1000).
    -v <l> : Log level. One of DEBUG, INFO, ERROR (default).

There is a tutorial that explains use case and function of the program: OpenCV practice: OCR for the electricity meter or OpenCV Praxis: OCR für den Stromzähler (in german language).

License

Copyright 2015,2021 Martin Kompf

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

emeocv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emeocv's Issues

Tweaked fork of emeocv

Hi Skarniga, thanks for Emeocv.
I've made some tweaks to your program to make a bit more reliable readings and to be able to use Raspberry Pi camera (or in fact any other medium of acquiring images). Let me know if you like the changes, perhaps we could merge to the code base?
https://github.com/wof2/emeocv

Keyboard action not détected.

I installed it on a Raspberry Zero and I control it with vnc.
When I start the first command 'emeocv -c0 -a -s10 -vINFO' it is impossible to have a action via the keyboard ( VNC) . If I push S Q or whatelse, I see the caracters but it have so action. The only thing working is ctrl-c.
So it was impossible to save the training file and after a got naturelly 'pi@raspberrypi:~/emeocv/Debug $ ./emeocv -i /home/pi/emeocv/images -t -s0
'Failed to load OCR training data' error message.
How can resolve this?

Unable to init server: Could not connect: Connection refused

After fixed the not working camera issues I got a new error. I run the following command:

sudo ./emeocv -c 0 -l

Then I got the follwoing error:

[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1824) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (914) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (501) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Unable to init server: Could not connect: Connection refused
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.1) ../modules/highgui/src/window_gtk.cpp:624: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

Aborted

What is my issue in this case?
Thanks in advance

make error

hi
when I try to build with make I got this error
kubuntu 18.04 LTS

g++ -Wno-write-strings -I . pkg-config opencv --cflags -g -D _DEBUG Debug/Directory.o Debug/Config.o Debug/ImageProcessor.o Debug/ImageInput.o Debug/KNearestOcr.o Debug/Plausi.o Debug/RRDatabase.o Debug/main.o pkg-config opencv --libs -lrrd -llog4cpp -o Debug/emeocv
/usr/bin/ld: /usr/local/lib/libopencv_videoio.a(cap_ffmpeg.cpp.o): undefined reference to symbol 'pthread_spin_trylock@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:44: recipe for target 'Debug/emeocv' failed
make: *** [Debug/emeocv] Error 1

Training data strange window

Hello Martin,

First of all, thanks for this awesome respository and website. Already learned a lot on OCR & OpenCV because of you.

However, whenever I fire up ./emeocv -i /docker/pics -l

I'm getting the following screen.

training

Is this normal? What should appear when training?

Thanks in advance,
Jérémy

Double counter meters

Good day,

First of all, thanks for the nice tool and its helpful tutorial.

However, I got stuck with the fact that I have an electricity meter with a double counter (normal and off peak). It is not a surprise that this won't work out of the box. I edited the config-file a bit to force the script to recognize digits from both counters (by increasing digitYAlignment), and during the 'adjust'-mode the digits are recognized. But during the OCR test-mode the digits are basically swapped from top to bottom from left to right (and of course a likely result of the config amendment).

I tried sorting the digits on its y-axis instead of the x-axis, but this did not work properly. Do you have any ideas or suggestions how to extract the digits from both counters? I must admit I am not very familiar with C++ at the moment, but I am willing to dive into it.

Kind regards.

Lediglich Terminalausgaben,

Hallo,

ich habe folgendes Problem:
Ich habe die Befehle wie folgt eingegeben:
image
Allerdings ist nie mehr passiert als diese Ausgabe.
Es wurden keinen Fenster geöffnet, nichts in die Datenbank eingetragen und in das angegebene Verzeichnis wurde auch nichts gespeichert.

Ich habe wie in der Dokumentation OpenCV-2.3.1 installiert und benutze Raspian 11 (bullseye).

Vielen Dank im voraus.

no executable found

Hi,
Thanks for this very interesting project and all the work done. I'm Sorry for the maybe stupid question but I followed tutorial to install emeocv. After the final "make" step, I can't execute the emeocv executable file as it seems to be not found. I tried to "locate" it but not found. I tested both on raspbian stretch & debian 5.2.9 without success. Did I miss something to be prepared in the environment ?
Thanks in advance for the support
Skyw43

Error when learning the digits

I'm trying to reproduce the whole process according to your tutorial. BTW, thank you - it's awesome.

When doing ./emeocv -i . -l -v DEBUG I get

OpenCV Error: Bad argument (train data must be floating-point matrix) in cvCheckTrainData, file /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/ml/src/inner_functions.cpp, line 857
terminate called after throwing an instance of 'cv::Exception'
what():  /build/opencv-92Ozt2/opencv-2.4.9.1+dfsg/modules/ml/src/inner_functions.cpp:857: error: (-5) train data must be floating-point matrix in function cvCheckTrainData

My trainctr.yml file looks too simple.

%YAML:1.0
samples: !!opencv-matrix
   rows: 0
   cols: 0
   dt: u
   data: []
responses: !!opencv-matrix
   rows: 0
   cols: 0
   dt: u
   data: []

Any help is appreciated.
P.S. I've only used your single example image for training. I've not setup my Rpi webcam yet.

Error While Running emeocv

Hi I try to run the software on a raspberri PI 3b+ with debian 11.4 (raspbian)

When I run:
sudo ./emeocv -c libcamerasrc -a -vINFO

I got this error:


[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1824) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Internal data stream error.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (914) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (501) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
INFO    : adjustCamera
Unable to init server: Could not connect: Connection refused
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.1) ../modules/highgui/src/window_gtk.cpp:624: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

Aborted

Any hints for me?

How many training samples for KNN?

How many samples were trained in your case for reliable digit recognition?
In other words: how many entries are there in training.yml file?

run on server

Hello. is't possibly to run it on no-display system? If yes, how to do it? Thanks!

Specify are of numbers

Not an Issue, but an question, is there a way to specify the area from where the numbers should be collected?

I have already closed the area with tape so that it is easier. but the numbers are never learned in learning mode ...

I would be very grateful for a tip.

Greetings

<a href="https://ibb.co/r5FMtkq"><img src="https://i.ibb.co/r5FMtkq/Ashampoo-Snap-Sonntag-9-Oktober-2022-20h28m45s.png" alt="Ashampoo-Snap-Sonntag-9-Oktober-2022-20h28m45s" border="0"></a>

OCR problem with 0/8

findContours() algorithm seems to ignore inner contours which makes 8 to be almost identical to 0.

figure 1_2017-05-23_12-49-18

I believe it's related to the CV_RETR_EXTERNAL parameter. After replacing it with CV_RETR_TREE I've got my inner contours working.

Any other suggestions?

Einzelne Zahl wird teilweise nicht als Zahl erkannt

Hallo, ich hoffe es ist okay wenn ich auf Deutsch schreibe, da Ihre Anleitung ja auch auf Deutsch ist. Erstmal möcht ich mich bedanken für die großartige Arbeit mit diesem Programm. Ich habe es als erstes mal mit diesen Arduino Infrarot Lichtschranken versucht die Drehscheibe am Zähler auszulesen aber nachdem das vorn und hinten nicht zuverlässig funktioniert hat, kam ich auf die Idee OCR zu nutzen, da ich noch eine alte IP Kamera liegen hatte. Das Tool hier ist also echt perfekt für meinen Anspruch.

Ich nutze einen Raspberry Pi 3 und der aktuellsten Raspbian Version. Die Installation war kein Problem und nach etwas ausprobieren, habe ich auch das Auslesen zum starten bekommen. Nach dem Anpassen der Canny-Werte waren die Zahlen auch schon ganz gut erkennbar. Nun bin ich gerade am anlernen der OCR Software, stelle aber immer wieder fest das mein Zählerstand nur so zu 70% voll ausgelesen wird. Mein Zählerstand ist 5-Stellig, als Beispiel ist der Zählerstand 1 3 4 6 5, die Software legt dann aber oft nur Boxen um 1 3 _ 6 5. Da wird dann zb die 4 nicht erkannt, obwohl die angelernt ist und auch genau so sichtbar und auf gleicher Höhe wie die anderen Zahlen. Das merkwürdige nun daran, teste ich es mit einem gleichen Bild ein paar Sekunden später geschossen, dann erkennt er plötzlich alle Zahlen. Obwohl das Bild in diesem Sinne genau gleich ist, vlt ist das Kamera-Rauschen ein wenig anders. Woran könnte das liegen? Sind das noch immer keine optimalen Canny Werte? Ich hab es auch mit diesem OCR Distanz Wert in der Config rumprobiert, da kann ich aber werte eintragen will ich will, das ändert gar nichts am auslesen. Gibt es eine Möglichkeit diese Canny-Werte irgendwie optisch sichtbar zu machen? So wie auf den Bildern in Ihrer Anleitung? Ich hab es mit dem -a Startparameter versucht, leider geht dann aber nur kurz das Bild auf, geht nach ein oder zwei Sekunden aber direkt wieder zu. Es ist im Moment nur ein Glücksspiel, wenn ich die Canny Werte abändere, ich weiss in diesem Sinne nicht was ich genau da ändere, ich sehe die Änderungen nur beim anlernen, wenn das Programm die einzelnen Zahlen erkennt (oder eben bei falschen Werten auch nicht).

Würde mich sehr über eine Antwort freuen, find das Programm echt super und möchte es später dann gerne nutzen um meine Zählerstände an OpenHab zu übertragen. Natürlich könnt ich mir noch eine Lösung einfallen lassen, dass eine weitere Prüfung stattfindet ob der ausgelesene Wert plausibel und korrekt ist aber toller wäre es natürlich, wenn ich die Erkennung noch optimieren kann.

Vielleicht gibt es noch zwei andere Fehlerquellen, die an der Kamera liegen. Zum einen hat die Kamera einen deutlich sichtbaren Fish-eye Effekt. Nicht so schlimm wie bei einer Actioncam aber an den Rändern wölben sich schon ein wenig Quadratische Boxen im Bild. Und zum anderen steht die Kamera relativ nah dran an dem Zähler, damit die Zahlen besser erkannt werden können. Aber vielleicht ist das gerade ja das Problem?

Hier mal ein Beispielbild, von einem Snapshot der ausgewertet werden soll.
P21031822044410

Vielen Dank erstmal und viele Grüße

Display not opening

Hello, I start emeocv on raspian via ssh, but the camera image can not be opened via X11. Then I installed the desktop environment of raspian, but it will not open a picture of the camera even if it is connected to a remote desktop. I use the raspberry camera modul i am not shure if this is the problem.it also indicates INFO : Image captured: 0
Please help me.

OCR low quality with 10x10 matrix

Hi,

in my case, the quality of OCR is very low. After training 447 samples I only get one correct digit in 100.

This is a visualization of my training data.

I've noticed that it's hard even for a human to recognize the shapes quickly and reliably. What can we do to improve the quality of OCR?

My only idea was to increase the sample size to 25x15 and try again. Please let me know if there's an easier way.

My original source image is well lit and adjusted to fit the screen.

Issue with make

g++ -Wno-write-strings -I . -g -D _DEBUG -c KNearestOcr.cpp -o Debug/KNearestOcr.o
In file included from KNearestOcr.cpp:18:0:
KNearestOcr.h:36:5: error: ‘CvKNearest’ does not name a type
CvKNearest* _pModel;
^
KNearestOcr.cpp: In constructor ‘KNearestOcr::KNearestOcr(const Config&)’:
KNearestOcr.cpp:21:9: error: class ‘KNearestOcr’ does not have any field named ‘_pModel’
_pModel(0), _config(config) {
^
KNearestOcr.cpp: In destructor ‘virtual KNearestOcr::~KNearestOcr()’:
KNearestOcr.cpp:25:9: error: ‘_pModel’ was not declared in this scope
if (_pModel) {
^
KNearestOcr.cpp:26:16: error: type ‘’ argument given to ‘delete’, expected pointer
delete _pModel;
^
KNearestOcr.cpp: In member function ‘char KNearestOcr::recognize(const cv::Mat&)’:
KNearestOcr.cpp:90:14: error: ‘_pModel’ was not declared in this scope
if (!_pModel) {
^
KNearestOcr.cpp:94:24: error: ‘_pModel’ was not declared in this scope
float result = _pModel->find_nearest(prepareSample(img), 2, results, neighborResponses, dists);
^
KNearestOcr.cpp: In member function ‘void KNearestOcr::initModel()’:
KNearestOcr.cpp:137:5: error: ‘_pModel’ was not declared in this scope
_pModel = new CvKNearest(_samples, _responses);
^
KNearestOcr.cpp:137:19: error: expected type-specifier before ‘CvKNearest’
_pModel = new CvKNearest(_samples, _responses);
^
KNearestOcr.cpp:137:19: error: expected ‘;’ before ‘CvKNearest’
make: *** [Debug/KNearestOcr.o] Error 1

Failed to load OCR training data

Hello,

I am having an issue in training the OCR. Everything works fine till learning which was accomplished by ./emeocv -i /home/pi -l
I provided the feedback digits to the recognized digits and saved it using key = 's'.

if (key != 'q' && ocr.hasTrainingData()) {
std::cout << "Saving training data\n";
ocr.saveTrainingData();
}

But I'm not able to get "Saving training data" which was supposed to from the above if condition.
Hence, when i run ./emeocv -i /home/pi -t -s0, I'm getting "Failed to load OCR training data".

Thanks for the help in advance...

std::out_of_range when training

Hello, I compiled emeocv with a freshly installed debian 9, but when I try to train it crashes.
$ Debug/emeocv -i png/ -l
Entering OCR training mode!
<0>..<9> to answer.....quit without saving.
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 9) > this->size() (which is 7)
Aborted
$

Feel free to ask for more details if needed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.