Skip to main content

License Plate Background Color

This software finds the background color of a license plate. It takes as input an image of a license plate (not the whole vehicle). And it is meant to be use in conjuction with Snapshot. The typical usage is as follows

  • Do a lookup on a full image using Snapshot.
  • Use the result to crop the license plate and save that image.
  • Send the cropped image to plate-color (see below).

Running the Docker Image#

  • Ask us for the SECRET_KEY. Contact us.
  • Install Docker if you do not have it.
  • Then run the following Docker command to start server.
    • Note: pass --gpus all to assign all gpus to the Docker container.
    • In this example the server port is set to 8501.
docker run -ti -e KEY=SECRET_KEY -p 8501:8501 platerecognizer/plate-color:latest

Plate Color Lookup#

The server expects a base64 encoded image of the license plate only. In the examples below, we use /path/to/plate.png.

With cURL#

curl -d "{\"instances\": [{ \"b64\":\"$(base64 -w0 /path/to/plate.png)\"}]}" \    http://localhost:8501/v1/models/classifier:predict

With Python#

import requestsimport base64with open(r'/path/to/plate.png', 'rb') as fp:    jpeg_bytes = base64.b64encode('utf-8')    predict_request = '{"instances" : [{"b64": "%s"}]}' % jpeg_bytes
    response =        'http://localhost:8501/v1/models/classifier:predict',        data=predict_request)    response.raise_for_status()print(response.json())


The output is the top 3 predictions for the background color. In this case, the most likely color is white with a score of .69 or 69%.

{    "predictions": [        {            "color": ["white", "blue", "black"],            "score": [0.69595, 0.0702599958, 0.06328]        }    ]}

End-to-end Example#

import base64import io
import requestsfrom PIL import Image
image_path = "car.jpg"token = 'xxx'with open(image_path, 'rb') as fp:    response =        '',        files=dict(upload=fp),        headers={'Authorization': f'Token {token}'},    )image = plate in response.json()['results']:    xmin = plate['box']['xmin']    ymin = plate['box']['ymin']    xmax = plate['box']['xmax']    ymax = plate['box']['ymax']    im_bytes = io.BytesIO()    image.crop((xmin, ymin, xmax, ymax)).save(im_bytes, 'JPEG', quality=95)    b64_data = base64.b64encode('utf-8')    predict_request = '{"instances" : [{"b64": "%s"}]}' % b64_data    response =        'http://localhost:8501/v1/models/classifier:predict', data=predict_request    )    print(response.json())