parkpow / deep-license-plate-recognition

Automatic License Plate Recognition (ALPR) or Automatic Number Plate Recognition (ANPR) software that works with any camera.
https://platerecognizer.com/
MIT License
523 stars 122 forks source link

Add split - grid_size #206

Closed ttayson closed 5 months ago

ttayson commented 5 months ago

Adding a grid to divide images

The feature maintains the previous pattern, dividing the image in two, and enables further division into more possibilities.

github-actions[bot] commented 5 months ago

Risk Level 2 - /home/runner/work/deep-license-plate-recognition/deep-license-plate-recognition/plate_recognition.py

The changes introduce a few potential issues that should be addressed:

  1. Exception for Missing Arguments: The exception raised when neither sdk_url nor api_key is provided should be more specific. Instead of a generic Exception, consider using ValueError which is more appropriate for invalid argument values.

    if not args.sdk_url and not args.api_key:
       raise ValueError(\"Either sdk_url or api_key must be provided\")
  2. API Key in Headers: Ensure that the API key is not logged or exposed in any way. If the API key is printed or logged somewhere in the code, it should be removed or obfuscated.

  3. Error Handling in API Calls: The code exits the script with exit(1) if the response status code is not successful and exit_on_error is True. This could be problematic if the script is part of a larger application. Consider raising an exception instead of exiting the script.

    if response.status_code < 200 or response.status_code > 300:
       print(response.text)
       if exit_on_error:
           raise RuntimeError('API call failed with status code: {}'.format(response.status_code))
  4. Text Width Calculation: The calculation of text_width seems to be incorrect as it tries to access a non-existent font.font attribute. It should be font.getsize(text) instead.

    (text_width, text_height) = font.getsize(text)
  5. Split Image Validation: The validation for args.split_x and args.split_y should check for positive values rather than just non-zero values to ensure that the image is split into a valid number of parts.

    if args.split_x <= 0 or args.split_y <= 0:
       raise ValueError(\"--split-x and --split-y must be positive integers\")

🔒🐛🚫


Powered by Code Review GPT

marcbelmont commented 5 months ago

@ttayson Can you please check Brian's version and confirm that it works with the client's image? If everything is good, please merge and share it with the client.

ttayson commented 5 months ago

@danleyb2 @marcbelmont , I ran tests and everything worked as expected.

The minimum accepted configuration is split-x=1 and split-y=1.

For a 3x3 grid, we have (3 + 1) (3 + 1) = 16 images. For a 2x2 grid, we have (2 + 1) (2 + 1) = 9 images. For a 2x1 grid, we have (2 + 1) (1 + 1) = 6 images. For a 1x1 grid, we have (1 + 1) (1 + 1) = 4 images.

Just as a suggestion, a small change from "or" to "and" might be considered, as both parameters are mandatory.