OCR for analog meter using opencv

Hi Guys,
I want to use the OpenCV platform to read off an analog water meter.

I’ve seen projects that use opencv to do that, but I am not sure how this could work with the Hass integration of the service. I’ve looked at the xml profiles for opencv and they all use body or face recognition.

Does anyone have opencv running recognition of something else apart from facial recognition?

This is the meter I want to read.

Did you ever found a way to solve this @Robster? We’ve got several analogue meters here in Belgium as well for water, electricity and gas.

At the moment I manually write down the current values on the first of every month, just to have a basic overview and store them in an input_number in HA.

@Robster @geoffrey Did you find a way to read this through a camera and input the reading in HA?

No sorry. I have come across several projects that attempt to build something like it outside of Home assistant, but am still hoping somebody has a ready to go solution for the meters locally in Belgium. :blush:

hi,

I did this for my electricity meter - I have a webcam pointed to it and amazon rekognition is reading the pic every half hour and sends a value to MQTT sensor.

On the chart above, the middle line is the reading. So I have a value which is upper limit for the delta on a new reading both up and down (yup, solar panels). If the OCR reading is not between the previous one +/- delta value - I assume the reading is wrong, no matter what accuracy rating Amazon gives back.

So if it fails a couple of times the boundary gets wider - if it finds a reading then the boundary is adjusted back to actual reading -/+ the delta for the next reading.

If you are interested and you are on Hassos and have the ability to install addons then I can share though I don’t have too much error handling in there and my ambition to become an application service provider is limited.

This is a sample of the picture that I’m looking at:

snip2

Unless your meter is in a cupboard, lighting conditions will change dramatically between night and a sunny afternoon - furthermore they sit behind plastic so you’ll have to deal with reflections and all of that.

Also the meter has a red dot on the 8 which makes it hard with semi-darkness in IR lighting - but now that your expectations are sufficiently managed you’ll find that it sort of works.

Jhh

2 Likes

some of the ESP32 camera modules have an LED on board for lighting up, you could have it turn on the LED to light it up enough to take a reading and then turn it back off?

plus you can adjust the focus to be very close, and theyre very cheap.

Yes this is exactly what I am looking for. I want to point it to a gas meter. The consumption is only few times a day , so two readings in a day also work for me. The meter is installed in a well lit , well ventilated area away from direct sunlight.

If you add repository https://github.com/jhhbe/hassio-addons in the HA addon store then you should be able to install. I’m on an RPI3 so I think architecture is only defined as available for armv7 though it is quite generic python so take a copy and put it in local addons if you need changes.

Jhh

1 Like

I am planning in building it by end of this month, using an ESP32 camera (for BE)… Will keep you posted

Very interesting. I a colleague of mine had a spare ESP32 cam that he gave me a while ago.

Due to the lack of skills and time, I had not imagined that it could be so soon perhaps a good candidate for this project.

If all goes well with your build, I’d be happy to follow along and create one on my own as well and share the experience.

In the meantime I have created a project with the esp32 cam module. I have been reading the values of my swimming pool monitoring screen.
What I noticed when using the camera, is that it needs quite some distance for the focus, meaning that for the analog utility meters you will need some space…

For the OCR part I used the https://ocr.space/ free API and scheduled it every 10 minutes.
Hope this already gives you some ideas :wink:


1 Like

That’s really cool!
About the focus: Did you try to put a small magnifying glass in front of the lens?

Hi,
I know it’s an old discussion but I am actually exactly looking for this solution to read my old gas and electric meter. The repository that @jhhbe shared doesn’t work (at least, the addons in it look deprecated - not supported anymore by HA).

Any chance to get it working with the current version of HA, or any other alternatives ?

Thanks

I only have low tech addon experience so I don’t have prebuilt images. In order to sort of make sure that they work I have only made them available for armv7 -I think- as I’m running on RPI 3B+ and they need to build on your pi.

If you let me know what it is complaining about I can have a look - ah - as it is now there is a constraint on the webcam which drops a pic in /config/www so you might want to check if you have that folder. It would be a fairly simple thing to make the webcam optional and use a jpg you can drop in that folder. An automation that drops a pic in the /config/www folder would take care of that.

Code snippet shows script is expecting a webcam supporting basic authentication and retrieves the snapshot in folder /config/www

    # download the url contents in binary format
    r = requests.get(config_json["url"], auth=(config_json["user"], config_json["password"]))
    # open method to open a file on your system and write the contents
    with open("/config/www/meter.jpg", "wb") as code:
        code.write(r.content)

hope that helps!
Jhh

I know that it’s not the same as OCR but I’ve got similar water meters and I’m reading them with infrared reflective sensors.

you can see the shiny-circle at the down-right side of the meter, just under the numbers. one full rotation of that circle means 1 liter is gone [at least in my meter ;)]. you just need to read this movement - and it’s fairly easy, as the circle has non-reflective part, the black triangle.

I’ve got the wemos mini d1, flashed tasmota on it, attached two TCRT5000 sensors, and prepared two tasmota rules that write the readout into tasmota’s counter variables. this way my meter is independent from the HomeAssistant [in case of reboots or any other issues], but HA ofcourse can read those counters via MQTT.

it will need some calibration [there’s a little screw on the sensor to do that] and it’s important to keep the meter & sensor in the dark as any additional light can mess with the readings and they jump hundreds of liters up :wink:

I’ve got this running for months now - works great and is very reliable after proper calibration. my meters are in the garage, enclosed in a small cabinet, so there’s no problem with lights leaks. additionaly I have temperature sensors attached to the very same wemos & plan to add PIR for motion detection, so it’s going to be a real multi-sensor setup, with almost no effort.

1 Like

Oh I’m running HA on a NUC, that’s probably why - too bad :frowning:

sounds exciting !

found some old pictures of first testing device:

okay - I’ve added architectures - as it is simple python I doubt there will be crazy dependencies. If you install it should build for your architecture and hopefully it will work.

Jhh

1 Like

Great thanks !
Unfortunately, I’ve just realized that an AWS account is needed (even though it’d be free the first 12 months), thus I don’t think I’m gonna use this solution permanently.