|
import os |
|
os.system('wget https://huggingface.co/spaces/An-619/FastSAM/resolve/main/weights/FastSAM.pt') |
|
|
|
import yolov5 |
|
|
|
|
|
model = yolov5.load('keremberke/yolov5m-license-plate') |
|
|
|
|
|
model.conf = 0.5 |
|
model.iou = 0.25 |
|
model.agnostic = False |
|
model.multi_label = False |
|
model.max_det = 1000 |
|
|
|
|
|
def license_plate_detect(img): |
|
|
|
results = model(img, size=640) |
|
|
|
|
|
results = model(img, augment=True) |
|
|
|
|
|
if len(results.pred): |
|
predictions = results.pred[0] |
|
boxes = predictions[:, :4] |
|
scores = predictions[:, 4] |
|
categories = predictions[:, 5] |
|
return boxes |
|
|
|
from PIL import Image |
|
|
|
import pytesseract |
|
|
|
def read_license_number(img): |
|
boxes = license_plate_detect(img) |
|
if boxes: |
|
return [pytesseract.image_to_string( |
|
image.crop(bbox.tolist())) |
|
for bbox in boxes] |
|
|