From fd1d6a9deb964c11e360c539b18e56f7d0494a8b Mon Sep 17 00:00:00 2001 From: gityashas <2yashas2@gmail.com> Date: Sat, 7 Sep 2024 23:07:02 +0530 Subject: [PATCH] fixed bugs caused due to frames without detections, other fixes --- anpr-system.py | 34 ++++++++++++++++++++-------------- requirements.txt | 19 ++++++++++--------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/anpr-system.py b/anpr-system.py index dd87577..02040c7 100644 --- a/anpr-system.py +++ b/anpr-system.py @@ -114,32 +114,43 @@ def filter_text(region, ocr_result, region_threshold): plate.append(result[1][0]) scores.append(result[1][1]) + if not plate: + return '', 0 + plate = ''.join(plate) plate = re.sub(r'\W+', '', plate) + if not scores: plate = '' scores.append(0) + return plate.upper(), max(scores) -def recognize_plate_easyocr(img, coords,reader,region_threshold): - """recognize license plate numbers using paddle OCR""" - # separate coordinates from box +def recognize_plate_easyocr(img, coords, reader, region_threshold): + """Recognize license plate numbers using PaddleOCR.""" xmin, ymin = coords[0] xmax, ymax = coords[1] - # get the subimage that makes up the bounded region and take an additional 5 pixels on each side - nplate = img[int(ymin):int(ymax), int(xmin):int(xmax)] ### cropping the number plate from the whole image + # Cropping the number plate from the image + nplate = img[int(ymin):int(ymax), int(xmin):int(xmax)] + try: nplate = clean(nplate) except: - return '',0 + return '', 0 + # Perform OCR on the cleaned number plate region ocr_result = reader.ocr(nplate) + + # Check if ocr_result is None or empty before proceeding + if ocr_result is None or len(ocr_result)==0 or ocr_result[0] is None or len(ocr_result[0])==0: + return '', 0 - text, score = filter_text(region=nplate, ocr_result=ocr_result, region_threshold= region_threshold) + text, score = filter_text(region=nplate, ocr_result=ocr_result, region_threshold=region_threshold) - if len(text) ==1: + if len(text) == 1: text = text[0].upper() + return text, score @@ -276,9 +287,4 @@ def main(weights_path, in_video, out_video, csv_path): args = parser.parse_args() if __name__ == '__main__': - main(args.weight, args.input, args.output, args.csv) - - - - - + main(args.weight, args.input, args.output, args.csv) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7d900c7..c5a915e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,10 @@ -matplotlib==3.5.1 -norfair==2.1.1 -numpy==1.23.5 -paddlepaddle-gpu==2.4.0 -paddleocr>=2.0.1 -pandas==1.4.3 -torch==1.13.0 -opencv_python_headless==4.5.4.60 -numpy==1.22.4 +matplotlib +norfair +numpy +paddlepaddle-gpu +paddleocr +pandas +torch +opencv_python_headless +torchvision +seaborn \ No newline at end of file