SSOCR - unable to detect digits

Hi All,

I’ve been at this debug for that last 4 hours. I started from this discussion and this documentation.

I’m using this image for testing:
test_ocr

Here’s my config and observations:
Configuration.yaml:

camera:

  • platform: local_file
    file_path: /media/test_ocr.png
    name: seven_segments_image

image_processing:

  • platform: seven_segments
    x_position: 0
    y_position: 0
    height: 73
    width: 280
    threshold: 20
    digits: 6
    source:
    • entity_id: camera.seven_segments_image

Sensor.yaml:

  • platform: template
    sensors:
    captured_time:
    value_template: “{{ states(‘image_processing.seven_segments’) }}”
    friendly_name: “Captured Time”
    unit_of_measurement: “”

Core LOGS: threshold : 20, 30

Logger: homeassistant.components.seven_segments.image_processing
Source: components/seven_segments/image_processing.py:143
Integration: seven_segments (documentation, issues)
First occurred: 11:53:36 AM (1 occurrences)
Last logged: 11:53:36 AM

Unable to detect value: unknown command “” found too many digits (7)

At threshold 40, I don’t get any core logs error, but the sensor : captured_time is empty (unknown)

Removing threshold and adding: extra_arguments: -T

Using this, I get empty (unknown) value and no logs.

So, any help/pointers would be appreciated
I see that those people seem to have made progress on this:
@calypso @nickrout @KCYeoh @PetrusB @Squalus

Please post your yaml properly.

1 Like

Yep, sure, BTW, no issue when I do check config.

I hope is the preformatted text option, seems the only one that works.

camera:
  - platform: local_file
    file_path: /media/test_ocr.png
    name: seven_segments_image

image_processing:
  - platform: seven_segments
    x_position: 0
    y_position: 0
    height: 73
    width: 280
#    threshold: 40
    extra_arguments: -T
    digits: 6
    source:
      - entity_id: camera.seven_segments_image

- platform: template
  sensors:
    captured_time:
      value_template: "{{ states('image_processing.seven_segments') }}"
      friendly_name: "Captured Time"
      unit_of_measurement: ""

You have threshold commented out.

Like I commented above, I tried threshold 20,30,40 and then removed it to use -T:

-T, --iter-threshold
Use an iterative method (one-dimensional k-means clustering) to determine the threshold used to distinguish black from white. A THRESHOLD value given via -t THRESHOLD sets the starting value.

When you read the doc from the SSOCR github, there are so many options!
https://www.unix-ag.uni-kl.de/~auerswal/ssocr/

The hard question to dig in is which options have been mapped to yaml config?
There’s no documentation that I could find that explain how HA integrated this SSOCR.

My understanding is that you can use any option in the ssocr docs in extra_arguments

I suggest trying it from the command line first as described in Setup Process

Yes, good idea from the command line, but from HAOS / Terminal, ssocr is not available. I’m unsure how I can run this on my HAOS bare metal server?

Alright, I managed to create an Unbuntu install, I compiled ssocr latest version and libraries.

I processed the same image as above in this thread with only those parameters and digits were OCR’ed.

image

Therefore, this program ssocr can work. The question is now, how to make it work from inside HA?

So I went back to the config and removed everything except -T in extra parameters and number of digits.

image_processing:

  • platform: seven_segments
    extra_arguments: -T
    digits: 6
    source:
    • entity_id: camera.seven_segments_image

But I got this error in the core logs:

Unable to detect value: ***** Imlib2 Developer Warning ***** : This program is calling the Imlib call: imlib_image_get_width(); With the parameter: image being NULL. Please fix your program

Ok then, thus the implementation of HA of ssocr is passing NULL values when we don’t specify width and possibly other parameters.

Again, where is this documented?

So I added back those parameters and restarted HA. No error in logs, but no detected value.

x_position: 0
y_position: 0
height: 73
width: 280

If I replicate those parameters on the command line, I get a good result.

So I’m stuck, unsure what to try next. Any ideas?

I poked around the source code of “image_processing.py”

I can see the parameters needed and their default. So I know my yaml parameters are OK.

image_processing:

  • platform: seven_segments
    x_position: 0
    y_position: 0
    height: 73
    width: 280
    rotate: 0
    threshold: 0
    extra_arguments: -T
    digits: 6
    source:
    • entity_id: camera.seven_segments_image

I simulated on the command line, those parameters, like above and they work. But on HA and I don’t get a response or error in the core log:

Could @fabaff (code owner) comment on this thread?

Thanks!

@piltous I saw that you managed to make ssocr work for you. Could you share your yaml configs? I would like to see if I’m missing something.

Thanks! Simon

Hi @SimonFili

Sure, I created 1st an automation that save a image of the camera (ESPHome esp-wrover-kit) also input numbers and other automation to avoid wrong values.

I hope it will help, also let me know.

Rgds

stream:

camera:

- platform: local_file
  file_path: /config/www/tmp/snapshot_water_meter_camera.jpg
  name: seven_segments_top

- platform: local_file
  file_path: /config/www/tmp/snapshot_water_meter_camera.jpg
  name: seven_segments_sub

image_processing:

  - platform: seven_segments
    x_position: 349
    y_position: 297
    height: 36
    width: 99
    digits: 4
    extra_arguments: -T
    source:
      - entity_id: camera.seven_segments_top

  - platform: seven_segments
    x_position: 454
    y_position: 300
    height: 27
    width: 56
    threshold: 37
    digits: 3
    source:
      - entity_id: camera.seven_segments_sub

template:

  - sensor:

      - name: "water_meter_top_check"
        unit_of_measurement: "m³"
        state: >
         {% set x = (states('image_processing.sevensegment_ocr_seven_segments_top') | float * 1 ) %}
         {% if x != 8888 %}
         {% if x != 'unknown' %}
          {{ ((x | float * 1 )| round (0)) }}
         {% else %}
          unavailable
         {% endif %}
         {% endif %}


The result if it can interest someone…

1 Like

try this. It looks like you do not use the last standard for template/sensor in your conf yaml ( Template - Home Assistant) ). I think the issue comes from your template

template:
  - sensor:
      - name: "Captured Time"
        unit_of_measurement: ""
        state: {{ (states('image_processing.sevensegment_ocr_seven_segments_image')) }}

You can test in 1st this template in http://homeassistant:8123/developer-tools/template

{{ (states('image_processing.sevensegment_ocr_seven_segments_image')) }}

Please post your yaml properly

You’re welcome :wink:

@piltous Julien, if you have a few minutes, I would like your input.

I’m trying to OCR this image:

The closest I found so far is using those parameters: (running in Ubuntu)

ssocr r_threshold crop 285 360 290 180 -d 1 -t 90 digits-9.jpg -o test.png

So this created this output file, which is quite good I think
image

But ssocr detect only 1 digit : 8

Any ideas?

Just do not do this. Not on the forum anyway. It’s banned.

hi @SimonFili ,

I only use the tool in HA but base on the doc:

-d, --number-digits RANGE
Specifies the number of digits shown in the image. Default value is 6. Use -1 to automatically detect the number of digits. Use a single positive number to specify an exact number of digits. Use two positive numbers separated with a hyphen (-) to specify an inclusive range of acceptable values for the number of digits.

you should put “-d 2”, no?

Yes -d 2 should be there, but since ssocr detect only 1, I wanted to see what was detected. Putting -d 2 give an error, only 1 detected.

Really no clue, nothing in automatic mode “- 1”?