Seven_segments, extra_arguments formatting?

It seems like I cant figure this out:

image_processing:
  - platform: seven_segments
    source:
      - entity_id: camera.laundrysensorcam
    x_position: 110
    y_position: 240
    height: 225
    width: 120
    threshold: 50
    digits : 3
    extra_arguments: '-D, invert, dilation 4'

This looks like I cant format the extra_arguments correctly. I have tried all these:

    extra_arguments: -D
    extra_arguments: '-D', 'invert', 'dilation 4'
    extra_arguments: "-D", "invert", "dilation 4"
    extra_arguments: '-D, invert, dilation 4'
    extra_arguments: -D, invert, dilation 4

And I think I have tried a couple more… Even when I use a single command, it doesnt seem to work. I have tested with -D which creates a resulting file to see the output. Well, this file never created so thats how I know it doesnt work.
Using the command line from the raspberry console, it works perfect.
Now, I know I can use the shell command and get the output but since this component already exists I think it is pointless.
Any help on how to correctly format the extra arguments?

[RPI3b+, Raspbian Stretch, HA 0.73.1]

Never used this before, but by looking at the documentation for ssocr and the code of this platform, I’d suggest removing the commas, and possibly not using -D. So:

extra_arguments: -D invert dilation 4

or

extra_arguments: invert dilation 4

I’m not sure you can/should use -D with this HA platform. Looking at the code the image is created in your HA configuration directory with a name of ocr.png.

I know the HA platform docs suggest using -D to figure out the parameters, but I’m pretty sure they mean by invoking the command in a shell for that, not with HA.

Are you getting any errors or warnings? Looks like in the code if it doesn’t work there should be at least a warning in the HA log.

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:

2 Likes

hi @argykaraz @pnbruckner

I’m trying to use seven segments function to read a gas meter but something doesn’t work in my configuration.

This is the photo:

this is the code I added in config

camera:
  - platform: local_file
    file_path: /config/www/camera/foto.png
    name: seven_segments
image_processing:
  - platform: seven_segments
    x_position: 390
    y_position: 250
    height: 280
    width: 490
    threshold: 20
    digits: 7
    source:
      - entity_id: camera.seven_segments

and these are de values shown, I use a static photo to check it

22

I can see something is not active or not accesible, I noticed there is created automatically a new file below but inside there is the same photo.
ssocr-SevenSegment_OCR_seven_segments.png

I don’t know how to go on.

Thanks for your help,

Hi from the present!

Did you ever get this sorted? I’m stuck at a similar place.

Hi from the present!

Did you ever get this sorted? I’m stuck at a similar place.

No, I think it is not working, I finally used https://ocr.space/ocrapi is very easy.

BR

Thanks … I got SSOCR working now - let me know if you want any more info.

hi,

i am trying to do the same
care to share your config :slight_smile: ?
how did you do it ?

regards

Hi! I haven’t visited here in ages … did you come right with this?

Almost a year later… I cannot get this to work, @emeyedeejay are you still able to provide more information?

According to HA, SSOCR is installed, I can setup the image processor which is either unknown or reading incorrectly. I am trying to run SSOCR in HA command line but it is not working, the command is not found, so I can’t really test if it’s processing the right image/ with the right arguments.

According to HA, SSOCR is installed, I can setup the image processor which is either unknown or reading incorrectly. I am trying to run SSOCR in HA command line but it is not working, the command is not found, so I can’t really test if it’s processing the right image/ with the right arguments.

Resolved - the processed image ended up in the config folder, I then added that to the UI so I can have a view and adjust the arguments based on this resource: Seven Segment Optical Character Recognition

Hi,
Would you mind sharing your code?
I have trouble making Seven Segments work with an analog counter but when I OCR the debug image with ocr.space, I get correct results.
Thanks!

Hi … just saw this now.

I got this far then needed to make a mount for my camera and I never got past that lol! That was pre 3D printer so maybe I will revisit.

image_processing:
#   - platform: seven_segments
#     x_position: 590
#     y_position: 557
#     width: 258
#     height: 94
#     source:
#       - entity_id: camera.seven_segs
#     extra_arguments: -D -S -d -1 shear 9 -t 39 7segs.jpg
#     #extra_arguments: -D crop 355 484 370 140 -S -d -1 shear 14 -t 10 7segs.jpg
    
#from testing with soccr in ubuntu docker container: ssocr -D crop 394 484 330 152 -S -d -1 shear 10 -t 10 7segs.jpg
# -D crop 355 484 370 140 -S -d -1 shear 14 -t 10 7segs.jpg

Is your analogue counter “slanted”? The shear parameter made all the difference to me I think.