Code Monkey home page Code Monkey logo

ocr-consumed-energy-logger's Introduction

ocr-consumed-energy-logger

Raspberry Pi project for logging OCR-ed readings from an energy meter.

About

This script is used to recognize readings from an energy meter like this:

Meter

and log them to Google Sheets for further analysis.

The project is merely an exercise with OpenCV and OCR, so the code could be helpful in situations when there's no other interfaces to get the readings. For more reliable setup it's probably better to use wired connections like P1 port or an optical interface. There's a number of projects that deal with IR readers:

Requirements

Hardware

In terms of the hardware the code has been tested on Raspberry Pi Zero W with ZeroCam module and the setup looks pretty much like this:

RPi front RPi back

For highlighting the scene 2 clear LEDs are used that work at 3.1V and draw 20mA. To turn them on we'll output a 3.3V signal on GPIO pins. Since the working voltage of an LED is lower we need to drop 3.3V down to 3.1V using dropping resitor. In order to calculate resistor parameters I used this calculator which gave me 10 ohm. More about controlling LEDs via GPIO.

Development setup

The image processing and readings extraction algorithm with experiments can be found in this Jupyter notebook. In order to run the notebook we'll need Python 3 and tesseract installed. My development box is running Mac OS, so the following steps will assume it:

user@macos$ brew install tesseract

It is advisable to install virtualenv and create new isolated environment in the project difrectory:

user@macos$ virtualenv venv
user@macos$ source venv/bin/activate

Then run pip to install development dependencies:

user@macos$ pip install -r requirements.txt

After that one should be able to run included Jupyter notebook in an environment of choice, for instance in VS Code.

Raspberry Pi setup

To run the energy logger code on Raspbian OS we need to install a number of dependencies. First, we need OpenCV dependencies and tesseract OCR engine. Note, that all the commands prefixed with user@raspberrypi will need to be executed on Raspberry Pi:

user@raspberrypi$ sudo apt-get update 
user@raspberrypi$ sudo apt-get install python3-opencv tesseract-ocr

Then create energy-logger user for running the app and add it to gpio and video groups:

user@raspberrypi$ sudo adduser energy-logger
user@raspberrypi$ sudo adduser energy-logger gpio
user@raspberrypi$ sudo adduser energy-logger video

Now, copy the app directory to the home directory of the energy-logger user. On the host computer run:

user@macos$ scp -r ./app [email protected]:~
[email protected]'s password:

Type energy-logger's password when asked. After command completes the app directory should appear in energy-logger user home directory. Note that it's rather bad security practice to allow ssh password authentication, but for the sake of simplicity we use Raspbian defaults here. Read here to learn how to disable SSH password authentication.

And then we can install energy logger Python dependencies (on the Raspberry Pi):

user@raspberrypi$ sudo su energy-logger
energy-logger@raspberrypi$ cd ~/app
energy-logger@raspberrypi$ pip install -r requirements.txt

Check this guide for installing camera on Raspberry Pi.

Additionally, you'll need to create new Google API project, create a service account and retrieve Google Sheets API access credentials in order to be able to log readings to a spreadsheet. Follow the guide here and save credentials to credentials.json file and put it to the app directory on Raspberry Pi. Also, don't forget to lock down file permissions (those are secrets after all):

energy-logger@raspberrypi$ chmod 600 credentials.json

Now, we need to schedule the logger to be executed let's say once every hour. To do that add the following line to /etc/crontab:

10 * * * * energy-logger SHEET_ID="{YOUR-SHEET-ID}" SHEET_RANGE="{YOUR-SHEET-RANGE}" /home/energy-logger/app/energy_logger.py 2>&1 | /usr/bin/logger -t energy-logger

where {YOUR-SHEET-ID} can be obtained from a Google Sheets document URL and {YOUR-SHEET-RANGE} should be something like Sheet1!A1:B1.

Credits

Tesseract traineddata for recognizing Seven Segment Display was taken from this great repository

ocr-consumed-energy-logger's People

Contributors

x-cray avatar

Watchers

 avatar

Forkers

szf2020

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.