I’d like to do OCR on my water and or electricity meter as both have no magpulse or opto stuff that can be used to sense the flow of water / electricity.
Has anyone done this before? They are not 7segment displays so that platform cannot be used.
I was thinking of buy a cheap IP cam but I am not sure how to hook this up to some OCR and end up with a number.
It works really well! Even when the number has rotated half. I did implement a safeguard (no negative delta’s and only 100L delta max). Sometimes there are still some false positives but with these, I can filter out most of them.
Hello,
I know the post is really old , but I just implemented a similar solution for this and thought it could help others:
As Skye, I’m using IP Camera on an Android device
I use Google Vision API for the recognition, it’s really powerfull
I created a script that turns on the light of the Android device, get the picture, turns off the light and sends the picture to Google Vision API, and push the results on an mqtt topic
I cron the script to be executed once a day
#!/bin/bash
data=/tmp/postData_$$.txt
img=/tmp/img_$$.jpg
resp=/tmp/resp_$$.txt
key=xxxxxxxx
test=false
beforeQuit(){
rm $data $img 2> /dev/null
rm $resp 2> /dev/null
}
trap beforeQuit EXIT
url=https://192.168.0.155:8080
#turn on flash
wget -q -O- --no-check-certificate $url/enabletorch > /dev/null
sleep 2
#download picture
wget -q -O $img --no-check-certificate $url/photo.jpg > /dev/null
#turn off flash
(sleep 1 && wget -q -O- --no-check-certificate $url/disabletorch > /dev/null) &
if $test
then
img=/tmp/IMG_3761.jpg
fi
cat <<EOF > $data
{"requests": [{"image": {"content": "$(base64 -w 0 "$img")"},"features": [{"type": "TEXT_DETECTION","maxResults": 10}]}]}
EOF
curl -s -X POST -H "Content-Type: application/json" -d @$data "https://vision.googleapis.com/v1/images:annotate?key=$key" > $resp
output=$(cat $resp | jq -r '.responses[0].fullTextAnnotation.text' | head -n1)
output=${output// /}
output=${output/m/}
if [[ $output =~ ^[0-9]+$ ]]
then
output=${output:0:5}.${output:5:9} #set the decimal point
echo $output
if $test
then
mosquitto_pub -u my_user -P my_password -t 'consumption/gas_test' -m "$output"
else
mosquitto_pub -u my_user -P my_password -t 'consumption/gas' -m "$output"
fi
else
echo "$output is not a number" 1>&2
beforeQuit
exit 1
fi
beforeQuit
Little sidenote, do take care of the phone’s battery. I had a moto x play whose battery didn’t like being plugged in for months on end and started to swell.
For this OCR case, I’m using an Xperia SP since, well, 2019 and so far no issues there, good old Sony quality
In the end it’s probably better to use an ESP-Cam and a bright LED, not something with a Li-Ion battery that’s constantly connected.
Could you elaborate more how to make this work on an old android phone?
I have an old S3 of which the simcard don’t work, but i might use it with WIFI for this purpose.
I’m really stuck trying to find an easy to implement soltion. I tried to reprogram my old TTGO Tjournal but my old code doesn’t seem to compile any longer
What about a “real” IP camera (used as generic camera in HA)?
I have some laying around and would like to work on this.
Is this nowadays possible with HA (sorry I am new).