mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 10:49:58 +00:00
Code voor kentekendetectie en cropping
Plus het model
This commit is contained in:
BIN
OCR YOLO11/license_plate_detector.pt
Normal file
BIN
OCR YOLO11/license_plate_detector.pt
Normal file
Binary file not shown.
37
OCR YOLO11/yolomain.py
Normal file
37
OCR YOLO11/yolomain.py
Normal 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()
|
||||
Reference in New Issue
Block a user