Things are indeed exactly as you mentioned! Thank you for the suggestions! It works the way you said. I had already found it, I am just messing with the settings right now and didnt answer with a solution until I was sure.
HA docs suggest using -D in a shell which I did. But I wanted to use -D in the configuration to make sure the arguments work. Which they didnt until I tried what u said. I will obviously delete -D as it is not needed.
Some tips for those that come with the same problem as me:
Height and Width are reversed when used in HA. So when ssocr says the first number is x and the second is y, HA also refers to those number with the same pattern, but the output is inversed!
So the output image when using shell is horizontal, and if you use it in HA it will be vertical!
The other settings are a bit confusing and they depend on the camera you use, the lighting in the room and more… You have to play around.
If you want to use -D the same way I did, be aware: the file is stored in /srv/homeassistant when you use it in HA. But it is stored in /home/pi when you use it in the console.
Also if you want to have another name for the file you must leave no spaces after -D.
here is my example:
image_processing:
- platform: seven_segments
name: UPSBattery
source:
- entity_id: camera.laundrysensorcam
x_position: 250
y_position: 100
height: 100
width: 135
threshold: 30
digits : 3
extra_arguments: dilation 3 -Dupsbat.png invert
I am now using the camera to read my UPS remaining battery.
Here is my whole setup for this:
camera:
- platform: mjpeg
mjpeg_url: http://192.168.1.3:8084 <<This is a usb attached camera streaming from Motioneye
name: LaundrySensorCam
username: !secret user
password: !secret camera
This is to see what the camera gives to the ocr engine
- platform: local_file
file_path: /home/homeassistant/.homeassistant/ocr.png
name: seven_segments_file
This is to see what kind of processing is done.
- platform: local_file
file_path: /srv/homeassistant/upsbat.png
name: UPSBatteryimg
And the final sensor to read the text
image_processing:
- platform: seven_segments
name: UPSBattery
source:
- entity_id: camera.laundrysensorcam
x_position: 250
y_position: 100
height: 100
width: 135
threshold: 30
digits : 3
extra_arguments: dilation 3 -Dupsbat.png invert
You can delete all the cameras except the one streaming.
I am using them temporarily to check if everything is ok.
Here is how it looks like: