Help with http post

hi, i want to implement plate recognizer number with openhab to open my gatedoor.
when a car trigger the camera detection openhab a snapshot and send a request to my sdk and i want to parse the result.
with shell command i obtain the result without problem.
this is the request from shell

davide@davide-OptiPlex-3040:~$ curl -F “upload=@/home/davide/Documenti/targa.jpg” http://192.168.1.8:38080/v1/plate-reader/

and this is the response:

“filename”: “targa.jpg”, “timestamp”: “2022-04-24 18:58:08.501118”, “camera_id”: null, “results”: [{“box”: {“xmin”: 420, “ymin”: 362, “xmax”: 540, “ymax”: 478}, “plate”: “", “region”: {“code”: “it”, “score”: 0.807}, “score”: 0.903, “candidates”: [{“score”: 0.903, “plate”: "*”}, {“score”: 0.781, “plate”: “fh6b7jy”}], “dscore”: 0.712, “vehicle”: {“score”: 0.686, “type”: “Van”, “box”: {“xmin”: 7, “ymin”: 0, “xmax”: 646, “ymax”: 604}}}], “usage”: {“calls”: 6, “max_calls”: 2500}, “processing_time”: 52.91

So i want to send the curl and parse the response, only the “plate”: “*****”, and if the plate is correct openhab open the doorgate.

i ve try to implement the http binding but i think that it’s not a good idea.
Do you think that 's possible to implement this request with the action for openhab?
this is the wiki of the sdk

HTTP Request
`POST https://api.platerecognizer.com/v1/plate-reader/

POST Parameters

Parameter Required Description
upload Yes The file to be uploaded. The parameter can either be the file bytes (using Content-Type multipart/form-data) OR a base64 encoded image.
regions No Match the license plate pattern of a specific region or regions. This parameter can be used multiple times to specify more than one region. It is treated as a guide and the template will be ignored if the prediction differs too much from it. That’s because we want to still be able to read plates from foreign vehicles. The system may sometimes mistake a local vehicle for a foreign one.
camera_id No Unique camera identifier.
timestamp No ISO 8601 timestamp. For example, 2019-08-19T13:11:25. The timestamp has to be in UTC.
mmc No Predict vehicle make, model, orientation and color. This feature is available for an additional fee. Set parameter to true (mmc=true) if you have this feature enabled/purchased to get vehicle make, model and color. Possible values are true or false.
config No Additional engine configuration. See details.

thank

That looks like JSON but it is missing its outer brackets?

If it were me, I would just implement that using scripting. JS Scripting, jruby, and jython are capable of dealing with this.

I am currently using jruby + this (free) docker based on openalpr: GitHub - sclaflin/OpenALPR-HTTP-Wrapper: Thin wrapper around the OpenALPR cli program

perfect, it’s the same thing that i ve trying to do.
how you send the request? through openhab?

Yes, I wrote a jruby script to manage the alert from my camera and send it to the docker/http-wrapper. It is working for me but I’m just monitoring the plates of the cars driving through the road in front of my house, so the camera angle is less than ideal and the cars aren’t stopping to pose for the camera :slight_smile: My script is relying on my camera’s (Dahua) motion detection feature + ipcamera binding to trigger my rule. I’ll clean up my script and post it in a bit.

I am also going to try the plate-minder docker. It is another layer on top of the http-wrapper. It will grab the stream directly from the camera and deal with the events. This may be less than ideal because it’s based on polling interval so it’ll continuously check every second or so. I’d imagine it’ll be more taxing on the cpu / gpu.

ok perfect, so i can study and try .
sorry but i’m not so good with script.
i check plate-minder, fantastic idea.
thank you so much

I think plate-minder might be the simplest solution - if it works. I haven’t managed to get it to work yet. Stuck at getting an RTSP stream from my camera but I haven’t spent much time with it.

@davideesse My code pulls camera snapshots from Blueiris instead of from the camera directly. It has been working fine this way.

Whilst cleaning up my code, I tried pulling the snapshots directly from the camera (Dahua), but I’m finding that the camera is too slow in returning the image that the vehicle has disappeared from view by the time I got the snapshot.

In your situation however, this may not be an issue other than longer delay, because the car that’s coming to the gate would have to sit and wait.

@davideesse I’ve posted my script here

You simply could send a request to openHABs API and update an item. No need to do anything within openHAB, except providing an item that get’s updated.

Hi , thank for your reply but i don’t understand. sorry.
i ve to send a curl request like this

curl -F “upload=@/home/davide/Documenti/targa.jpg” http://192.168.1.8:38080/v1/plate-reader/

and parse the reply. it’s possible trough openhab? what command or binding i have to try for my purpose?

thank you so much