ljmerza / frigate_plate_recognizer

Identify license plates via Plate Recognizer and add them as sublabels to Frigate
120 stars 15 forks source link

Script broken with the update #34

Closed danielszilagyi closed 7 months ago

danielszilagyi commented 7 months ago

Hello,

I found your project a while ago, and spent some time on making it usable as a HaOS addon, and made it configurable from the UI.

I have very narrow Python experience but also noticed some ratelimits when sending the same image from two cameras in a similar timeframe, so I added a 2 seconds limit in plate_recognizer(image) and this all worked nicely until I noticed that there was a merge yesterday and pulled the new changes into my branch. I also modified the paths and made them configurable from environment in favor of the addon beforehand. Everything looked fine until the updates with watched plates yesterday.

The script stops working at the moment of a detection, and I cannot see anything that is connected to my changes.

I ended up copying the unmodified script, and modifying only the path variables, still getting the below error. I was using test camera streams and the script dies at the moment event is received.

I did not add anything fuzzy / watched plates configuration, could this be the problem? It is mentioned as optional. Couldn't figure out what is the missing 3rd value in the last error...

Here is the error:

2024-02-11 19:32:01,833 - __main__ - DEBUG - Getting snapshot for event: 1707676321.214615-er4zb2, Crop: True
2024-02-11 19:32:01,834 - __main__ - DEBUG - event URL: http://ccab4aaf-frigate-fa:5000/api/events/1707676321.214615-er4zb2/snapshot.jpg
2024-02-11 19:32:01,991 - __main__ - DEBUG - Getting plate for event: 1707676321.214615-er4zb2
2024-02-11 19:32:03,749 - __main__ - DEBUG - response: {'processing_time': 49.087, 'results': [{'box': {'xmin': 484, 'ymin': 524, 'xmax': 606, 'ymax': 563}, 'plate': 'suz804', 'region': {'code': 'hu', 'score': 0.122}, 'score': 0.901, 'candidates': [{'score': 0.901, 'plate': 'xxxxxx'}], 'dscore': 0.783, 'vehicle': {'score': 0.507, 'type': 'Motorcycle', 'box': {'xmin': 372, 'ymin': 241, 'xmax': 731, 'ymax': 630}}}], 'filename': '1832_zvqnF_upload.jpg', 'version': 1, 'camera_id': None, 'timestamp': '2024-02-11T18:32:03.622879Z'}
2024-02-11 19:32:03,750 - __main__ - DEBUG - Skipping checking Watched Plates because watched_plates is not set
Traceback (most recent call last):
  File "/usr/src/app/./index2.py", line 583, in <module>
    main()
  File "/usr/src/app/./index2.py", line 579, in main
    run_mqtt_client()
  File "/usr/src/app/./index2.py", line 538, in run_mqtt_client
    mqtt_client.loop_forever()
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/usr/src/app/./index2.py", line 472, in on_message
    plate_number, plate_score, watched_plate, fuzzy_score = get_plate(snapshot)
                                                            ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/./index2.py", line 397, in get_plate
    plate_number, plate_score , watched_plate, fuzzy_score = plate_recognizer(snapshot)
                                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/app/./index2.py", line 134, in plate_recognizer
    watched_plate, watched_score, fuzzy_score = check_watched_plates(plate_number, response['results'][0].get('candidates'))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

Any ideas @gadget-man @ljmerza ?

danielszilagyi commented 7 months ago

I solved it by changing line 146:

return None, None, None

I will not close the issue as I also wanted to discuss if there is rationale in PR'ing the HaOS addon stuff.

ljmerza commented 7 months ago

fixed in v1.8.12