这是代码
from ultralytics import YOLO
license_plate_detector = YOLO('./model/best.pt')
license_plates = license_plate_detector('./42.jpg')
这是输出
640x608 1 number-plate, 342.0ms
Speed: 12.4ms preprocess, 342.0ms inference, 3.0ms postprocess per image at shape (1, 3, 640, 608)
我想将此输出转换为图像并将其保存以与 esyocr 一起使用
该类没有任何保存方法,那么如何执行此操作
我想,这会对你有帮助。
from PIL import Image
from ultralytics import YOLO
import easyocr
license_plate_detector = YOLO('./model/best.pt')
input_image = Image.open('./42.jpg')
detections = license_plate_detector(input_image)
license_plate_boxes = detections.xyxy[0].cpu().numpy()
reader = easyocr.Reader(['en'])
for i, box in enumerate(license_plate_boxes):
x1, y1, x2, y2, conf, cls = box
license_plate = input_image.crop((x1, y1, x2, y2))
plate_filename = f'license_plate_{i}.jpg'
license_plate.save(plate_filename)
results = reader.readtext(plate_filename)
print(f"License Plate {i+1} Text: {results[0][1]}")