Code voor kentekendetectie en cropping

Plus het model
This commit is contained in:
zoloko13
2025-06-10 10:16:07 +02:00
parent 9287541cb5
commit 78854fa84f
2 changed files with 37 additions and 0 deletions

Binary file not shown.

37
OCR YOLO11/yolomain.py Normal file
View File

@@ -0,0 +1,37 @@
from ultralytics import YOLO
from ultralytics.utils.downloads import safe_download
from ultralytics.utils.plotting import Annotator, colors
from PIL import Image
import os
os.chdir("C:/Users/celma/OneDrive - Hanze/School/periode 1.4/IOT/YOLO11/License Plate Recognition.v11i.yolov11")
crop_dir_name = "C:/Users/celma/OneDrive - Hanze/School/periode 1.4/IOT/YOLO11/License Plate Recognition.v11i.yolov11/test/crops"
if not os.path.exists(crop_dir_name):
os.makedirs(crop_dir_name)
model = YOLO("license_plate_detector.pt") # Loads the pre-trained YOLO11 model
names = model.names
results = model.predict("test/images/000c.jpg", show=True, save=True)
img = Image.open("test/images/000c.jpg") # Load the original image using PIL
boxes = results[0].boxes.xyxy.cpu().tolist()
clss = results[0].boxes.cls.cpu().tolist()
# annotator = Annotator(results[0], line_width=2, example=names)
#print(results)
print(boxes)
if boxes is not None:
for box, cls in zip(boxes,clss):
# annotator.box_label(box, color=colors(int(cls), True), label=names(int(cls)))
crop_obj = boxes[int(box[1]):int(box[3]) + int(box[0]):int(box[2])]
cropped_img = img.crop(
(int(box[0]), int(box[1]), int(box[2]), int(box[3]))
)
save_path = os.path.join(crop_dir_name, "cropped_image.jpg")
cropped_img.save("cropped_image.jpg")
cropped_img.show()