Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions anpr-system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
19 changes: 10 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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