ZoneMinder / zmeventnotification

Machine Learning powered Secure Websocket & MQTT based ZoneMinder event notification server
412 stars 128 forks source link

platerecognizer.com SDK call fails #236

Closed connectnet closed 4 years ago

connectnet commented 4 years ago

Event Server version = 5.9.9

Hooks version = 5.9.9

The version of ZoneMinder you are using: = 1.34.6

What is the nature of your issue = Bug

Details I installed the platerecognizer sdk and tested it with: curl -F 'file=@/tmp/car.jpg' http://localhost:8080/alpr Its works good and I only have to setup the platerecognizer TOKEN and LICENSE_KEY during the docker installation and I dont need later an api-key. So I uncommend in objectconfig.ini in the [alpr] part:

# If you want to host a local SDK https://app.platerecognizer.com/sdk/
alpr_url=http://localhost:8080

Debug Logs (if applicable)

Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 417, in <module>
    options=options)
  File "/usr/local/lib/python3.6/dist-packages/zmes_hook_helpers/alpr.py", line 67, in __init__
    AlprBase.__init__(self, url, apikey, tempdir)
  File "/usr/local/lib/python3.6/dist-packages/zmes_hook_helpers/alpr.py", line 15, in __init__
    raise ValueError('Invalid or missing API key passed')
ValueError: Invalid or missing API key passed

Thanks!

pliablepixels commented 4 years ago

Please post your full [alpr] section

connectnet commented 4 years ago
[alpr]
# keep this to yes. no mode is not supported today
alpr_use_after_detection_only=yes
# plate_recognizer, open_alpr, open_alpr_cmdline
alpr_service=plate_recognizer
# If you want to host a local SDK https://app.platerecognizer.com/sdk/
alpr_url=http://localhost:8080
# Plate recog replace with your api key
alpr_key=!PLATEREC_ALPR_KEY
# if yes, then it will log usage statistics of the ALPR service
platerec_stats=no
# If you want to specify regions. See http://docs.platerecognizer.com/#regions-s
upported
#platerec_regions=['us','cn','kr']
# minimal confidence for actually detecting a plate
platerec_min_dscore=0.1
# minimal confidence for the translated text
platerec_min_score=0.2
pliablepixels commented 4 years ago

You need to add the key back into the config.

connectnet commented 4 years ago
sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py -c /etc/zm/objectconfig.ini -e 249 -m 1 
[s] detected:car:100% --SPLIT--[{"type": "object", "label": "car", "box": [46, 102, 706, 570], "confidence": "99.72%"}]

It doesnt lookup the SDK. I add the PLATEREC_ALPR_KEY into the secret.ini file but where I have to add the SDK License Key?

pliablepixels commented 4 years ago

Look at DEBUG logs. Post them. Also, according to http://docs.platerecognizer.com/#sdk, alpr_url needs to be http://localhost:8080/alpr

connectnet commented 4 years ago

03/13/20 14:28:19 zmesdetect_m1[7831] INF zm_detect.py:150 [---------| app version: 5.9.9 |------------] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:254 [secret filename: /etc/zm/secrets.ini] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ZM_PORTAL] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ZM_API_PORTAL] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ZM_USER] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ZM_PASSWORD] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ML_USER] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !ML_PASSWORD] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_num_jitters default: 0] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_upsample_times default: 1] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_model default: hog] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_train_model default: hog] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_recog_dist_threshold default: 0.6] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:face_recog_knn_algo default: ball_tree] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:known_images_path default: /var/lib/zmeventnotification/known_faces] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:unknown_images_path default: /var/lib/zmeventnotification/unknown_faces] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:unknown_face_name default: unknown face] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:save_unknown_faces default: yes] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:224 [Section [face] missing in config file, using key:save_unknown_faces_leeway_pixels default: 50] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:227 [Secret token found in config: !PLATEREC_ALPR_KEY] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:277 [allowing self-signed certs to work...] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:wait with value:5] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:detect_pattern with value:.*] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:detection_mode with value:all] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:302 [adding polygon: myway [0,0 1163,0 1547,514 1327,1067 0,1076 0,270]] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:models with value:yolo,alpr] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:frame_id with value:bestmatch] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:296 [[monitor-1] overrides key:match_past_detections with value:no] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [config] is '/var/lib/zmeventnotification/models/yolov3/yolov3.cfg' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [weights] is '/var/lib/zmeventnotification/models/yolov3/yolov3.weights' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [labels] is '/var/lib/zmeventnotification/models/yolov3/yolov3_classes.txt' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [tiny_config] is '/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.cfg' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [tiny_weights] is '/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.weights' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] DBG utils.py:331 [key [tiny_labels] is '/var/lib/zmeventnotification/models/tinyyolo/yolov3-tiny.txt' after substitution] 03/13/20 14:28:19 zmesdetect_m1[7831] INF zm_detect.py:170 [Importing local classes for Yolo/Face] 03/13/20 14:28:19 zmesdetect_m1[7831] INF utils.py:99 [Sleeping for 5 seconds before downloading] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG utils.py:140 [Trying to download http://localhost/zm/index.php?view=image&eid=249&fid=alarm&username=user&password=*****] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG utils.py:158 [Trying to download http://localhost/zm/index.php?view=image&eid=249&fid=snapshot&username=user&password=*****] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG zm_detect.py:226 [resizing to 1200 before analysis...] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG utils.py:35 [resized polygons x=0.625/y=0.625: [{'name': 'myway', 'value': [(0, 0), (726, 0), (966, 321), (829, 666), (0, 672), (0, 168)]}]] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG zm_detect.py:247 [User ALPR if vehicle found: True] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG zm_detect.py:325 [Using model: yolo with /var/lib/zmeventnotification/images/249-alarm.jpg] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG yolo.py:48 [|---------- YOLO (input image: 1200w*675h, resized to: 416w*416h) ----------|] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG yolo.py:59 [Initializing Yolo] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG yolo.py:61 [config:/var/lib/zmeventnotification/models/yolov3/yolov3.cfg, weights:/var/lib/zmeventnotification/models/yolov3/yolov3.weights] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG yolo.py:83 [Not using CUDA backend] 03/13/20 14:28:24 zmesdetect_m1[7831] DBG yolo.py:88 [YOLO initialization (loading model from disk) took: 126.324 milliseconds] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG yolo.py:103 [YOLO detection took: 757.38 milliseconds] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG yolo.py:136 [YOLO NMS filtering took: 0.98 milliseconds] 03/13/20 14:28:27 zmesdetect_m1[7831] INF yolo.py:162 [object:car at [1034, 13, 1200, 175] has a acceptable confidence:0.9873764514923096 compared to min confidence of: 0.3, adding] 03/13/20 14:28:27 zmesdetect_m1[7831] INF yolo.py:162 [object:stop sign at [938, 119, 974, 205] has a acceptable confidence:0.6729039549827576 compared to min confidence of: 0.3, adding] 03/13/20 14:28:27 zmesdetect_m1[7831] INF yolo.py:162 [object:car at [1046, 204, 1200, 650] has a acceptable confidence:0.6594047546386719 compared to min confidence of: 0.3, adding] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG image_manip.py:133 [intersection: polygon in process=[(1034, 13), (1200, 13), (1200, 175), (1034, 175)]] 03/13/20 14:28:27 zmesdetect_m1[7831] INF image_manip.py:158 [object:car at POLYGON ((1034 13, 1200 13, 1200 175, 1034 175, 1034 13)) does not fall into any polygons, removing...] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG image_manip.py:133 [intersection: polygon in process=[(938, 119), (974, 119), (974, 205), (938, 205)]] 03/13/20 14:28:27 zmesdetect_m1[7831] INF image_manip.py:158 [object:stop sign at POLYGON ((938 119, 974 119, 974 205, 938 205, 938 119)) does not fall into any polygons, removing...] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG image_manip.py:133 [intersection: polygon in process=[(1046, 204), (1200, 204), (1200, 650), (1046, 650)]] 03/13/20 14:28:27 zmesdetect_m1[7831] INF image_manip.py:158 [object:car at POLYGON ((1046 204, 1200 204, 1200 650, 1046 650, 1046 204)) does not fall into any polygons, removing...] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG zm_detect.py:516 [There was no vehicle detected by Yolo in this image] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG zm_detect.py:583 [No match found in /var/lib/zmeventnotification/images/249-alarm.jpg using model:yolo] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG zm_detect.py:325 [Using model: yolo with /var/lib/zmeventnotification/images/249-snapshot.jpg] 03/13/20 14:28:27 zmesdetect_m1[7831] DBG yolo.py:48 [|---------- YOLO (input image: 1200w*675h, resized to: 416w*416h) ----------|] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG yolo.py:103 [YOLO detection took: 796.028 milliseconds] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG yolo.py:136 [YOLO NMS filtering took: 1.862 milliseconds] 03/13/20 14:28:31 zmesdetect_m1[7831] INF yolo.py:162 [object:car at [46, 102, 706, 570] has a acceptable confidence:0.9971526861190796 compared to min confidence of: 0.3, adding] 03/13/20 14:28:31 zmesdetect_m1[7831] INF yolo.py:162 [object:car at [1052, 198, 1204, 556] has a acceptable confidence:0.7691580653190613 compared to min confidence of: 0.3, adding] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG image_manip.py:133 [intersection: polygon in process=[(46, 102), (706, 102), (706, 570), (46, 570)]] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG image_manip.py:140 [myway intersects object:car[[(46, 102), (706, 102), (706, 570), (46, 570)]]] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG image_manip.py:133 [intersection: polygon in process=[(1052, 198), (1204, 198), (1204, 556), (1052, 556)]] 03/13/20 14:28:31 zmesdetect_m1[7831] INF image_manip.py:158 [object:car at POLYGON ((1052 198, 1204 198, 1204 556, 1052 556, 1052 198)) does not fall into any polygons, removing...] 03/13/20 14:28:31 zmesdetect_m1[7831] DBG zm_detect.py:405 [Invoking ALPR as detected object is a vehicle or, we are trying hard to look for plates...]

pliablepixels commented 4 years ago
  1. Did you fix the alpr_url like my comment above?
  2. What happens after zm_detect.py:405 [Invoking ALPR as detected object is a vehicle or, we are trying hard to look for plates...] ?
connectnet commented 4 years ago
  1. yes = http://localhost:8080/alpr
  2. Than comes the next detection call from another video
    03/13/20 14:36:49 zmesdetect_m1[7897] INF zm_detect.py:150 [---------| app version: 5.9.9 |------------]
    03/13/20 14:36:49 zmesdetect_m1[7897] DBG utils.py:254 [secret filename: /etc/zm/secrets.ini]
connectnet commented 4 years ago

03/13/20 15:56:44 zmesdetect_m1[9145] DBG alpr.py:111 [Plate recognizer rejected the upload. You either have a bad API key or a bad image] The PLATEREC_ALPR_KEY is correct (checked twice), the picture is detected correct via API call but not via SDK call.

pliablepixels commented 4 years ago

okay in that case the SDK probably expects a different format of the image if your API key is ok. I haven't tried the local SDK. I'll do so in a few days.

connectnet commented 4 years ago

Thanks a lot for your time!

connectnet commented 4 years ago

I did not notice that the docker crashes. So after restart the docker file the log stops after:

3/13/20 16:55:10 zmesdetect_m1[2050] DBG zm_detect.py:405 [Invoking ALPR as detected object is a vehicle or, we are trying hard to look for plates...]
03/13/20 16:55:10 zmesdetect_m1[2050] DBG alpr.py:73 [PlateRecognizer ALPR initialized with options: {'regions': None, 'stats': 'no', 'min_dscore': 0.1, 'min_score': 0.2} and url: http://localhost:8080/alpr]
03/13/20 16:55:10 zmesdetect_m1[2050] DBG alpr.py:39 [supplied object is a file]

and the console says:

sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py -c /etc/zm/objectconfig.ini -e 268 -m 1 
Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 439, in <module>
    alpr_b, alpr_l, alpr_c = alpr_obj.detect(filename)
  File "/usr/local/lib/python3.6/dist-packages/zmes_hook_helpers/alpr.py", line 114, in detect
    response = response.json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

pliablepixels commented 4 years ago

I unfortunately can't test the SDK. It requires a license key that is paid.

connectnet commented 4 years ago

I don't know how, but I can you send my license key for free or ask my friends from platerecognizer to give you a test SDK.

pliablepixels commented 4 years ago

Ok, if you can get me access to the SDK (or even open up your SDK server over the internet) I can test.

pliablepixels commented 4 years ago

Please update to the latest release and test the SDK. Works for me.

Notes:

  1. set alpr_api_type to local
  2. You no longer need to specify an API key in objectconfig.ini if you are using the local SDK

Please note that

  1. if the docker image of plate recognizer crashes/etc, you'll have to reach out to them for support
  2. I don't proactively plan to keep updating the code to support any API changes they do in the future to the local SDK. If that happens, you should first check with platerecognizer

Thx

pliablepixels commented 4 years ago

I am closing as this is assumed to be resolved.