Convert images of analog gauge to readings
Project description
README
Ever stared at an old analog gauge - like that dusty water meter in your basement - and wished you could convert its indicators into actionable data?
ppf.angauge (pronounced like "engage") to the rescue: It converts photos of
your gauge to digital readings. It handles
- meters with a single indicator showing an analog value (like an ammeter or the gauge in the logo)
- meters having multiple indicators each showing a digit [0, 10) of the actual reading (like the water meter shown below).
Note: It reads indicators (hands rotating in front of dials). It does not read registers (rotating drums with printed digits).
It provides:
- a python package to integrate into your own projects
- a command line tool for quick testing and prototyping
Isn't this very similar to "AI-on-the-edge"? It is. In fact, if you are looking for a firmware to run on an esp32-cam board, you are better off using that project. If you are working on a different platform, if you want the flexibility to integrate with your own (python) code, or if you are reading value-indicators (not digit-indicators), keep reading.
Usage
The command-line tool works as follows:
> read_gauge <config.toml> <image.bmp>
image.bmp, 0.5632
where config.toml is a configuration file specifying location, size, and
orientation of the indicators in image.bmp, which we will explain in a
second. For more information on command line options, see read_gauge --help.
The following code snippet shows how to do the same in python:
from ppf.angauge import read_config, read_multi_gauge, mle
from matplotlib.pyplot import imread
# read configuration file:
config = read_config('config.toml')
# read image:
img = imread('image.jpg')
# read meter hands from image:
readings = read_multi_gauge(img, config)
# determine most likely meter state given readings:
value, errorbar = mle(readings)
If you have a large set of images to process, you may value GNUs parallel`
tool. Leverage it as follows:
> printf "%s\0" *.bmp | parallel -0 -L 64 read_gauge <config.toml> \
| sort | tee -a readings.csv
Let's break this down step by step:
printf "%s\0" *.bmpgenerates a null-separated list of all.bmpfiles in the current directory. The null-separation avoids problems with filenames that contain spaces or special characters. Furthermore,printfavoids problems with (very) long argument lists: If you have a really large number of images, just usingls *.bmpmay result inzsh: argument list too long.parallel -0 -L 64 read_gauge <config.toml>runsread_gauge <config.toml> <image>for each image in the list.-0tellsparallelthat the input list is null-separated.-L 64tellsparallelto take 64 input arguments at a time and give them as arguments to a singleread_gaugecall. This is much more efficient than runningread_gaugeonce per image, because it avoids the overhead of loading the python interpreter for each image.parallelwill use all CPU cores in your system. If you want it to use less, use the-jargument.sort: Sorts the output ofread_gaugetee -a readings.csv: Print results on screen but simultaneously also append them toreadings.csv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ppf_angauge-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ppf_angauge-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01b156f63b0034e6f2cc8e241b619eb92912d2e2c7141e68a869ae80e96b92d7
|
|
| MD5 |
38643d073db29c478e86f70fa88cdea8
|
|
| BLAKE2b-256 |
475f6b13d8b826be925113909675e969229418d99a4a7b098837d7ab7d1a3e2d
|