platerec


Nameplaterec JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/pstwh/platerec
SummaryRead license plates
upload_time2024-07-26 21:15:24
maintainerNone
docs_urlNone
authorNone
requires_python<4,>=3.5
licenseNone
keywords plate ocr read brazilian
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # platerec

`platerec` is a lightweight package for reading license plates using an ONNX model. It is designed to be part of a pipeline for detecting, cropping, and reading license plates. The underlying model is a mobilenetv2 as encoder and a light gpt for decoder. The training data comprises primarily Brazilian license plates, sourced from internet images, also synthetic data generated in the same font with transforms. The model repository can be found [here](https://github.com/pstwh/platerec-model).

## Installation

To install the required dependencies, use the following command:

For cpu

```bash
pip install "platerec[cpu]"
```

For cuda 11.X
```bash
pip install "platerec[gpu]"
```

For cuda 12.X
```bash
pip install "platerec[gpu]" --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/
```

## Usage

### Command Line Interface

You can use the command line interface to detect license plates in an image:

```bash
platerec image_path [--encoder_path ENCODER_PATH] [--decoder_path DECODER_PATH] [--return_types RETURN_TYPE] [--providers PROVIDERS] [--platedet]
```

#### Arguments

- `image_path`: Path to the input image. Could be more than one image.
- `--encoder_path`: Path to the ONNX encoder model (default: `artifacts/encoder.onnx`).
- `--decoder_path`: Path to the ONNX decoder model (default: `artifacts/decoder.onnx`).
- `--return_type`: Output formats (choices: `word`, `char`). Word return the plate text and confidence detected, char return the plate chars detected with confidences for each char.
- `--providers`: ONNX Runtime providers (default: `CPUExecutionProvider`).
- `--platedet`: Use platedet to detect plates first. Will first detect plates and then read them.

### Example

To just read an already cropped image:

```bash
python3 platerec/cli.py examples/1.jpg --return_type word
```

To detect license plates and read them:

```bash
python3 platerec/cli.py examples/1.jpg --return_type word --platedet
```

### Using in Code

To just read an already cropped image:

```python
from PIL import Image
from platerec import Platerec

platerec = Platerec()
image = Image.open('examples/1.jpg')
pred = platerec.read(image)
```
pred will be something like:
```
{'word': 'ZZZ1Z11', 'confidence': 0.98828125}
```

To detect license plates and read them:

```python
from PIL import Image
from platerec import Platerec

platerec = Platerec()
image = Image.open('examples/1.jpg')
crops = platerec.detect_read(image)
for idx, crop in enumerate(crops['pil']['images']):
    crop.save(f'{idx}.jpg')
```

pred will be something like:
```
{'images': [<PIL.Image.Image image mode=RGB size=105x40 at 0x7FEE25B67AD0>], 'confidences': array([0.72949219]), 'words': ['AAA1A11'], 'boxes': array([[ 393, 1188,  498, 1228]], dtype=int32), 'words_confidences': [0.95263671875]}
```

If you want to use CUDA:
```python
from platerec import Platerec

platerec = Platerec(providers=["CUDAExecutionProvider"])
```

Check all execution providers [here](https://onnxruntime.ai/docs/execution-providers/).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pstwh/platerec",
    "name": "platerec",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.5",
    "maintainer_email": null,
    "keywords": "plate, ocr, read, brazilian",
    "author": null,
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# platerec\n\n`platerec` is a lightweight package for reading license plates using an ONNX model. It is designed to be part of a pipeline for detecting, cropping, and reading license plates. The underlying model is a mobilenetv2 as encoder and a light gpt for decoder. The training data comprises primarily Brazilian license plates, sourced from internet images, also synthetic data generated in the same font with transforms. The model repository can be found [here](https://github.com/pstwh/platerec-model).\n\n## Installation\n\nTo install the required dependencies, use the following command:\n\nFor cpu\n\n```bash\npip install \"platerec[cpu]\"\n```\n\nFor cuda 11.X\n```bash\npip install \"platerec[gpu]\"\n```\n\nFor cuda 12.X\n```bash\npip install \"platerec[gpu]\" --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/\n```\n\n## Usage\n\n### Command Line Interface\n\nYou can use the command line interface to detect license plates in an image:\n\n```bash\nplaterec image_path [--encoder_path ENCODER_PATH] [--decoder_path DECODER_PATH] [--return_types RETURN_TYPE] [--providers PROVIDERS] [--platedet]\n```\n\n#### Arguments\n\n- `image_path`: Path to the input image. Could be more than one image.\n- `--encoder_path`: Path to the ONNX encoder model (default: `artifacts/encoder.onnx`).\n- `--decoder_path`: Path to the ONNX decoder model (default: `artifacts/decoder.onnx`).\n- `--return_type`: Output formats (choices: `word`, `char`). Word return the plate text and confidence detected, char return the plate chars detected with confidences for each char.\n- `--providers`: ONNX Runtime providers (default: `CPUExecutionProvider`).\n- `--platedet`: Use platedet to detect plates first. Will first detect plates and then read them.\n\n### Example\n\nTo just read an already cropped image:\n\n```bash\npython3 platerec/cli.py examples/1.jpg --return_type word\n```\n\nTo detect license plates and read them:\n\n```bash\npython3 platerec/cli.py examples/1.jpg --return_type word --platedet\n```\n\n### Using in Code\n\nTo just read an already cropped image:\n\n```python\nfrom PIL import Image\nfrom platerec import Platerec\n\nplaterec = Platerec()\nimage = Image.open('examples/1.jpg')\npred = platerec.read(image)\n```\npred will be something like:\n```\n{'word': 'ZZZ1Z11', 'confidence': 0.98828125}\n```\n\nTo detect license plates and read them:\n\n```python\nfrom PIL import Image\nfrom platerec import Platerec\n\nplaterec = Platerec()\nimage = Image.open('examples/1.jpg')\ncrops = platerec.detect_read(image)\nfor idx, crop in enumerate(crops['pil']['images']):\n    crop.save(f'{idx}.jpg')\n```\n\npred will be something like:\n```\n{'images': [<PIL.Image.Image image mode=RGB size=105x40 at 0x7FEE25B67AD0>], 'confidences': array([0.72949219]), 'words': ['AAA1A11'], 'boxes': array([[ 393, 1188,  498, 1228]], dtype=int32), 'words_confidences': [0.95263671875]}\n```\n\nIf you want to use CUDA:\n```python\nfrom platerec import Platerec\n\nplaterec = Platerec(providers=[\"CUDAExecutionProvider\"])\n```\n\nCheck all execution providers [here](https://onnxruntime.ai/docs/execution-providers/).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Read license plates",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/pstwh/platerec"
    },
    "split_keywords": [
        "plate",
        " ocr",
        " read",
        " brazilian"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "758e906adedd3c02b9b770b5006366c848b6b3f5c6d49e9a5f9378a9048ca9ba",
                "md5": "ff07d7472a6309e7c99d7f83cbb120ed",
                "sha256": "5e1c5c7752fd4e1236543cdd2a8a9b4ff6df820c9f38009531e58de3f06d3b96"
            },
            "downloads": -1,
            "filename": "platerec-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ff07d7472a6309e7c99d7f83cbb120ed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.5",
            "size": 8353880,
            "upload_time": "2024-07-26T21:15:24",
            "upload_time_iso_8601": "2024-07-26T21:15:24.635900Z",
            "url": "https://files.pythonhosted.org/packages/75/8e/906adedd3c02b9b770b5006366c848b6b3f5c6d49e9a5f9378a9048ca9ba/platerec-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-26 21:15:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pstwh",
    "github_project": "platerec",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "platerec"
}
        
Elapsed time: 0.37644s