[Solved] DeepStack ALPR Blue Iris Integration Help Needed

I am working on an API to integrate a DeepStack ALPR into Blue Iris. I have a Python script done that does the ALPR and now I want to make it an API. I am still learning Python and are have issue to get a test API working. For the test I am trying to save the JPEG file that Blue Iris is sending

Thank
Mike

Below is what Blue Iris is sending (Wireshark Capture)

Ei@àf0¾~Jc5`P@ðPOST /ALPR HTTP/1.1
Authorization: Token test123test123
Content-Length: 410575
Content-Type: multipart/form-data; boundary=3ec729cbea21475f
User-Agent: Blue Iris
Host: 127.0.0.1:5000
Cache-Control: no-cache

EKk@àf0¾~ìJc5`Pp--3ec729cbea21475f
Content-Disposition: form-data; name="timestamp"
2022-01-13T06:17:29.000Z

--3ec729cbea21475f
Content-Disposition: form-data; name="camera_id"
Cam6

--3ec729cbea21475f
Content-Disposition: form-data; name="upload"; filename="car.jpg"
Content-Type: image/jpeg

Test API code

import os
import json

from flask import Flask, request
from werkzeug.utils import secure_filename

UPLOAD_FOLDER = '/test'

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

@app.route("/APLR", methods=["GET", "POST"])
def APLR():
    if request.method == 'POST':
        timestamp = request.form['timestamp']
        camera_id = request.form['camera_id']
        upload = request.files['upload']
        car_jpg = request.form['car.jpg']
        filename = secure_filename(upload.filename)
        upload.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        print(timestamp + camera_id + car_jpg)

    return json.dumps({
    "processing_time": 288.758,
    "results": [
        {
            "box": {
                "xmin": 143,
                "ymin": 481,
                "xmax": 282,
                "ymax": 575
            },
            "plate": "nhk552",
            "region": {
                "code": "gb",
                "score": 0.747
            },
            "vehicle": {
                "score": 0.798,
                "type": "Sedan",
                "box": {
                    "xmin": 67,
                    "ymin": 113,
                    "xmax": 908,
                    "ymax": 653
                }
            },
            "score": 0.904,
            "candidates": [
                {
                    "score": 0.904,
                    "plate": "nhk552"
                }
            ],
            "dscore": 0.99,
            "model_make": [
                {
                    "make": "Riley",
                    "model": "RMF",
                    "score": 0.306
                }
            ],
            "color": [
                {
                    "color": "black",
                    "score": 0.937
                }
            ],
            "orientation": [
                {
                    "orientation": "Front",
                    "score": 0.937
                }
            ]
        }
    ],
    "filename": "car.jpg",
    "version": 1,
    "camera_id": "Cam6",
    "timestamp": "2020-10-12T16:17:27.574008Z"
})


app.run(debug=True)  # debug=True causes Restarting with stat

Error

 * Serving Flask app 'aplr' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 840-360-619
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [13/Jan/2022 20:34:39] "POST /ALPR HTTP/1.1" 404 -

Sorry I haven’t done this. Can you explain the intended sequence for me, and where it errors or fails?

maybe check…
-items in json.dumps (names, #, format, etc) I was thinking the POST could be getting rejected if not as expected. (also, i cant recall, but should ‘xmin et al’ values be between 0 and 1?).
-connection. can you send any info between them successfully? All permission, network, and firewalls sorted? keep it simple.

Hope you can sort, it looks like a great project!

@shallowstack I also posted the issue on Reddit and found the solution. It was a typo the highlighted both need to be the same “/ALPR”


1 Like