OCR for analog meter using opencv

hi,

Thanks for that remark - you’re right only first year is free. I’ll need to change my refresh frequency to once every hour to stay below 1000 images per month soon. 1USD for 1K images seems reasonable until our meters are swapped to digital meters with a P1 service port that we can read (it will also be more accurate as Rekognition is not perfect).

I had missed that - I thought I could stay in the free tier for quite long.

Thx!
Jhh

Hi,

First of all a great idea to read the meters like this and thanks for sharing your hard work. I got it all working with creating an image and making the connection to AWS. But then it somehow fails with the following log output. I have no idea what that could mean. I would really appreciate your help:

x i x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
i
0 0 2
-----------
Tekst: H
Type: WORD
Confidence 67.27286529541016
Id 6
ParentId: 0
value conversion
x H x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
H
0 0 2
-----------
Tekst: e
Type: WORD
Confidence 50.415550231933594
Id 8
ParentId: 1
value conversion
x e x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
e
0 0 2
-----------
Tekst: W
Type: WORD
Confidence 46.646087646484375
Id 7
ParentId: 0
value conversion
x W x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
W
0 0 2
-----------
Tekst: 20
Type: WORD
Confidence 74.04178619384766
Id 9
ParentId: 2
value conversion
x 20 x
Nw:  20
-----------
Tekst: 0049m
Type: WORD
Confidence 94.37973022460938
Id 10
ParentId: 3
value conversion
x 0049m x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
0049m
0 0 2
-----------
Tekst: LLLIIIW
Type: WORD
Confidence 70.71917724609375
Id 11
ParentId: 4
value conversion
x LLLIIIW x
Conversion failed
Nw:  0
erg waarschijnlijk juist:
LLLIIIW
0 0 2
-----------
Tekst: 41622252324
Type: WORD
Confidence 88.07597351074219
Id 12
ParentId: 4
value conversion
x 41622252324 x
Nw:  41622252324
-----------
Reading = ok
Traceback (most recent call last):
  File "ocr_aws.py", line 112, in <module>
    baseline = int(reading)
ValueError: invalid literal for int() with base 10: 'LLLIIIW'
[cmd] /run.sh exited 1
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.```

Thanks,
Thomas

hi,

When AWS is reading the text in an image it does not by magic return the correct answer. It gives you a number of guesses with a confidence rating (though I doubt at Amazon they like that phrasing).

That is why I need a current reading with a =/- range so the script can work out if the reading makes sense (new reading is between old one - delta value and old one + delta value) as the confidence ratings don’t really work.

It also means the script is trying to treat a lot of gibberish as numbers so it looks like there is an is numerical check which is not working. I’ll have a look at that but my python is not great.

Given that it sees so much in your picture you may want to change the camera angle a bit, reflections are not good. Can you include a pic of the meter that you are using?

Jhh

@jhhbe

Hi, thanks very much for this addon! Exactly what I was looking for. :slight_smile:
However I can’t install it due to error : “Failed to install addon, Unknown Error, see logs”. I’m on Hassio 0.113 on a rpi3b.

Here is my supervisor log:

20-07-28 09:12:34 INFO (SyncWorker_7) [supervisor.docker.addon] Start build 47b59106/armv7-addon-meterreader:0.1.16
20-07-28 09:12:49 ERROR (SyncWorker_7) [supervisor.docker.addon] Can’t build 47b59106/armv7-addon-meterreader:0.1.16: The command ‘/bin/ash -o pipefail -c pip3 install boto3’ returned a non-zero code: 127

Thanks!

UPDATE : I could install boto3 manually using “pip3 install boto3” in terminal, but the install still hangs on the same message.
UPDATE 2 : solved. We need to create a build.json file according to this post
UPDATE 3 : actually you are amazing you already solved it with a different way :slight_smile: thanks so much

@alexbelgium,

ha, yes I posted a new version a bit earlier today. The whole setup is a bit picky as it requires a quite similar setup to what I had. If you got this far I assume you’ll manage. Good find on that fix - I’ll probably include that as it seems more reliable than what I came up with.

I’m not putting too much time in this anymore - I’ve repurposed the webcam to find out what animal is after our chickens and we’re getting a smart meter sooner or later.

Good luck! Should you get stuck; just ask.

Jhh

2 Likes

@jhhbe
well it works perfectly so thanks very much. It now reads the camera snapshot and saves the data to the MQTT sensor as expected :slight_smile:

For the chicken what I did is use the motioneye addon to capture motion… Its not perfect on rpi3b but just works. And I built an arduino-managed co-op door that opens and closes based on luminosity. It was tricky to set but now works rather well.

All the best,
Alexandre

Hi,
what’s the code to read numbers and text? What i’ve to write in the targets?
Thank you

  • platform: amazon_rekognition
    aws_access_key_id: *****
    aws_secret_access_key: *****
    region_name: eu-west-1 # optional region, default is us-east-1
    save_file_folder: /config/www/amazon-rekognition/ # Optional image storage
    save_timestamped_file: True # Set True to save timestamped images, default False
    confidence: 90 # Optional, default is 80 percent
    targets: # Optional target objects, default person
    • ???
      roi_x_min: 0.2 # optional, range 0-1, must be less than roi_x_max
      roi_x_max: 0.6 # optional, range 0-1, must be more than roi_x_min
      roi_y_min: 0.3 # optional, range 0-1, must be less than roi_y_max
      roi_y_max: 0.45 # optional, range 0-1, must be more than roi_y_min
      source:
    • entity_id: camera.water_meter

Here was my full options that worked very well. I didn’t put targets and it provided all readable numbers with high probability as output.

upd_interval: 1800
url: 'http://192.168.178.52:8080/cgi-bin/snapshot.sh'
user: 'null'
password: 'null'
baseline: '617550'
under: 10
over: 10
aws_access_key_id: ACCESSKEY
aws_secret_access_key: SECRETKEY
region: us-east-2
mqtt_host: 192.168.178.23
mqtt_port: 1883
mqtt_user: mqtt
mqtt_pwd: mqtt
mqtt_topic: home/meterelectricity

Hi, I know it’s quite an old thread but would you mind elaborating on your solution? Thanks

Hello, got an Aquarite LT from Hayward (apparently no RS485 on this model). I’d like to do the same with OCR, can you share your Yaml plz ?
Thx.

Hi, I don’t have the code anymore, but in fact I did the OCR processing on the server, not on the ESP