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 script and guide to repo #214

Closed dibonjohnseron closed 2 weeks ago

github-actions[bot] commented 2 weeks ago

Risk Level 3 - /home/runner/work/deep-license-plate-recognition/deep-license-plate-recognition/plate_background_color.py

The code changes introduce several new functions and imports, which could potentially impact the stability and performance of the system. Here are some specific concerns and suggestions:

  1. Exception Handling: The try-except blocks in post_image_for_blur and predict_color functions catch broad exceptions, which can make debugging difficult. It's better to catch specific exceptions.

    try:
       # existing code
    except requests.exceptions.HTTPError as e:
       logger.error(f\"HTTP error: {e}\")
    except requests.exceptions.ConnectionError as e:
       logger.error(f\"Connection error: {e}\")
    # add more specific exceptions as needed
  2. Hardcoded URLs: The URLs in post_image_for_blur and predict_color are hardcoded, which makes the code less flexible and harder to maintain. Consider using configuration files or environment variables.

    BLUR_API_URL = os.getenv('BLUR_API_URL', 'https://blur.platerecognizer.com/v1/blur')
    PREDICT_API_URL = os.getenv('PREDICT_API_URL', 'http://localhost:8501/v1/models/classifier:predict')
  3. Security Risk: Storing API keys in code, even as arguments, can be a security risk. Ensure that API keys are not logged or exposed in error messages.

  4. Image Processing: The crop_box function does not validate the box dictionary for the presence of the required keys ('xmin', 'xmax', 'ymin', 'ymax'). This could lead to KeyError if the dictionary is missing any of these keys.

  5. Global Variables: The logger is set up as a global variable, which might not be thread-safe if the script is used in a multi-threaded context. Consider passing the logger as an argument to functions that need it.

  6. File Handling: The save_results function does not handle potential exceptions that can occur during file operations, such as IOError if the file cannot be written to.

  7. Argument Validation: The validate_crop_percentage function raises an ArgumentTypeError for invalid values, but the error message could be more descriptive by including the invalid value provided by the user.

  8. Code Duplication: The flatten_dict function is recursive and has duplicated code for checking if the key is 'result'. This could be simplified to reduce redundancy.

  9. Performance: The get_aspect_ratio function calculates distances between all points in a polygon, which can be inefficient for polygons with many points. Consider optimizing this calculation if the polygon has a known structure, such as a rectangle for license plates.


🐛🔒🚀


Powered by Code Review GPT

marcbelmont commented 2 weeks ago

It is already in https://github.com/parkpow/internal-tools/tree/main/scripts/plate-background-color