OpenALPR local not working

Trying to get local OpenALPR to work on my setup. Have tried it with different camera’s, they all give an image on my dashboard. There is also the Image processing block on my dashboard, with ‘OpenAlpr cam_test Onbekend’ in it. Onbekend is Dutch for ‘unknown’.

Basic config is as follows:

camera:
  - platform: generic
    still_image_url: http://plates.openalpr.com/h786poj.jpg
    name: cam_test

image_processing:
 - platform: openalpr_local
   region: eu
   source:
    - entity_id: camera.cam_test

I’m running the official docker container on a Raspberry PI 3+. If I go into the container and test the alpr binary, it works:

bash-4.4# alpr http://plates.openalpr.com/h786poj.jpg
Video stream connecting...
Video stream connected
Stream http://plates.openalpr.com/h786poj.jpg?openalprfiletype=file.mjpg received invalid frame
plate0: 10 results
    - 786P0      confidence: 90.3854
    - 786PO      confidence: 79.5375
    - 786PQ      confidence: 78.7093
    - 786PD      confidence: 74.781
    - 7B6P0      confidence: 73.7773
    - 786PU      confidence: 71.7058
    - 7B6PO      confidence: 62.9293
    - 7B6PQ      confidence: 62.1012
    - 7B6PD      confidence: 58.1729
    - 7B6PU      confidence: 55.0976

Home Assistant log-file shows no errors on imageprocessing and/or alpr.

One thing I found was that the documentation says I need OpenALPR version 2.3.1, but the official docker container comes with OpenALPR 2.3.0. But there doesn’t seem to be a 2.3.1 anywhere.

bash-4.4# alpr --version

alpr  version: 2.3.0

Switching the config to openalpr_cloud works fine:

plates { "H786POJ": 93.548583984375, "H786PO": 80.3131332397461, "H786PJ": 80.28873443603516, "H786P0J": 80.04952239990234, "H786POX": 80.03324890136719, "H786PQJ": 80.03030395507812 }

vehicles 1

Any ideas on what I can check next?

I’ve got the same issue, did you ever find a solution?
I ate through the cloud credits in no time, so could do with it working locally.

2 Likes

Same issue. It seems that few people if any have actually got this working.

Ok so i thought i’d find a way to make this work. This is my solution.
The command line binary alpr works fine at returns the Number Plate data. So just needed a way to work with it for now.

So i setup a shell command :

shell_command:
  garage_number_plate: alpr -c gb /home/homeassistant/.homeassistant/www/alerts/garage_outdoor_camera.jpg -j  > /home/homeassistant/.homeassistant/NumberPlates/garage_outdoor_plates.json

This will be triggered by a motion event automation


# Motion Alerts
- id: Garage Motion Image Processing
  initial_state: true
  alias: Garage Motion Image Processing
  trigger:
    platform: state
    entity_id: binary_sensor.garage_motion
    to: "on"
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.garage_outdoor_camera
        filename: "/home/homeassistant/.homeassistant/www/alerts/garage_outdoor_camera.jpg"
    - service: image_processing.scan
      data:
        entity_id: image_processing.garage_face_identify
    - service: image_processing.scan
      data:
        entity_id: image_processing.garage_face
    - service: shell_command.garage_number_plate

If it finds number plate data the shell command will save it to file and then this sensor can read the file

sensor 46:
  - platform: file
    name: Garage Number Plate
    file_path: /home/homeassistant/.homeassistant/NumberPlates/garage_outdoor_plates.json
    value_template: '{{value_json["results"][0]["plate"]}}'

I can then display the contents of those sensors on a Lovelace dashboard or use the response to fire more automation’s. i.e

- id: Local ALPR Number Plate Listener Garage
  alias: Local ALPR Number Plate Listener Garage
  trigger:
    platform: state
    entity_id: sensor.garage_number_plate
  condition:
    condition: template
    value_template: "{% if not is_state('sensor.garage_number_plate', 'XXXXXXX') and not is_state('sensor.garage_number_plate', 'XXXXXXX') and not is_state('sensor.garage_number_plate', 'XXXXXXX') and not is_state('sensor.garage_number_plate', 'XXXXXXX') and not is_state('sensor.garage_number_plate', 'unknown') %}true{% endif %}"
  action:
    service: notify.gavin_home_dashboard
    data_template:
      title: Home Security Alert - Garage Camera ALPR
      message: >
        'Unknown Car on Drive with Number Plate {{ states("sensor.garage_number_plate") }} {{ now().strftime("%H:%M %d/%b") }}'
      data:
        image: "https://home.assistant.url:8123/local/alerts/garage_outdoor_camera.jpg?{{now().second}}{{now().second}}{{range(1000)|random}}"
        url: "https://home.assistant.url:8123/api/camera_proxy_stream/camera.garage_outdoor_camera"
        actions:
          - action: tv_lamp_on
            icon: "/local/tv.png"
            title: TV / Lamp On
          - action: intruder_alert
            icon: "/local/Alarm-128.png"
            title: Activate Intruder Alert
        priority: high
        tag: 'garage-outdoor-motion-plate_{{ now().strftime("%Y%m%d-%H%M%S") }}'

or

- id: Local ALPR Number Plate Listener Garage Daddy Home
  alias: Local ALPR Number Plate Listener Garage Daddy Home
  trigger:
    platform: state
    entity_id: sensor.garage_number_plate
  condition:
    condition: template
    value_template: "{% if is_state('sensor.garage_number_plate', 'DADDY') %}true{% endif %}"
  action:
    - service: tts.google_translate_say
      data:
        entity_id: media_player.lounge_speaker
        message: Daddys Car is pulling on the Drive
    - service: notify.gavin_home_dashboard
      data_template:
        message: >
          'Daddys Car is pulling on the Drive {{ now().strftime("%H:%M %d/%b") }}'
      data:
        data:
          priority: high
          tag: "daddy-car-arrived-home-garage"

Hope this helps someone get it working

4 Likes

Shell Command? I didn’t see anything about that in the documentation. Is it necessary for it to work?

Could you possibly show your image_processing.scan setup in the config file.

Gavin, really helpful share.

I’m running hassio on a VirtualBox VM as I’m on Windows. Do you know what I’d need to do to use a shell command? Do I need to create a separate VM for OpenALPR to run in

Is HassIO running on a Windows OS or just VirtualBox running on Window with some linux distro behind it.
I run my HA on a Ubuntu VM in HyperV
You can build a Windows binary for OpenALPR https://github.com/peters/openalpr-windows if necessary
http://doc.openalpr.com/on_premises.html
there is also a docker container you could run yourself https://hub.docker.com/r/openalpr/openalpr/

Hi

Building the Windows Binary option

HassIO works as a Virtual Box as itself - so they have different IP to the windows PC.

How does 1 communicate with the other as in the configuration doesn’t seem to have anywhere to specify (might be being very stupid here)

maybe you could put the alpr binary as a subdirectory of your config folder.
or run a docker add on in HassiO. TBH i have never used HassIO

Where do you put your file in the ubuntu environment?

What do you use to trigger the motion? The camera motion detector im guessing from your code… Wondering if its better to have the openalpr daemon monitor the camera feed then use a Http Post command? Not used that before, think that would work to trigger an automation

the file is in the /usr/bin dir and it is called from anywhere, because its set in the %PaTH% variable. You can do the same for the windows VM, not sure how its built though.

The motion is triggered from Blue Iris sending a MQTT message to HA.

It would probably be pretty intensive monitoring it constantly, thats why i only do it when triggered.

Have it working in docker that has alpine as base image.

#Adding of dependencies
echo “http://nl.alpinelinux.org/alpine/edge/testing” >>/etc/apk/repositories && echo -e “http://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/main” >> /etc/apk/repositoriesapk --no-cache add --virtual .build-deps ca-certificates wget git gcc g++ cmake make curl-dev leptonica-dev log4cplus-dev opencv-dev tesseract-ocr-dev libexecinfo-dev
#Cloning and making of directories
cd /srv && git clone https://github.com/openalpr/openalpr.git && cd openalpr/src && mkdir build && cd build && sed -i.bak ‘s/backtrace/0;///’ …/daemon.cpp
#building
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc … && make -j8 && make install

as for using it, openalpr config does not work but a workaround from gavinwoolley here makes it usable. OpenALPR local not working

If you need help editing config etc just reach out.

I’d be interested in knowing how you work with the Docker container for ALPR - does it havea REST API of sorts?

I’m currently running OpenALPR from an Ubuntu container, calling ALPR through SSH command from my HA (which is running through Docker)

1 Like

i’d like to know how to do this also… running HA on a VM and trying to run OpenALPR on docker on QNAP Container station