mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 10:49:58 +00:00
Werkend ANPR systeem
This commit is contained in:
41
ANPR.py
Normal file
41
ANPR.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from ultralytics import YOLO
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import easyocr
|
||||
|
||||
car_model = YOLO("yolov8n.pt")
|
||||
plate_model = YOLO("license_plate_detector.pt")
|
||||
reader = easyocr.Reader(["nl"])
|
||||
|
||||
img = Image.open("test.jpg")
|
||||
|
||||
results = car_model.predict(source=img)
|
||||
|
||||
for r in results:
|
||||
for box in r.boxes:
|
||||
cls_id = int(box.cls[0])
|
||||
cls_name = r.names[cls_id]
|
||||
if cls_name == "car":
|
||||
conf = float(box.conf[0])
|
||||
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
||||
print(f"{cls_name} ({conf:.2f}) at [{x1},{y1},{x2},{y2}]")
|
||||
|
||||
# Crop Image
|
||||
cropped_img = img.crop((x1, y1, x2, y2))
|
||||
cropped_img.save("car_crop_pillow.jpg")
|
||||
results2 = plate_model.predict(source=cropped_img)
|
||||
for x in results2:
|
||||
for box2 in x.boxes:
|
||||
cls_id = int(box2.cls[0])
|
||||
cls_name = x.names[cls_id]
|
||||
if cls_name == "License_Plate":
|
||||
conf = float(box2.conf[0])
|
||||
x1, y1, x2, y2 = map(int, box2.xyxy[0])
|
||||
print(
|
||||
f"{cls_name} ({conf:.2f}) at [{x1},{y1},{x2},{y2}]"
|
||||
)
|
||||
lp_img = cropped_img.crop((x1, y1, x2, y2))
|
||||
lp_img.save("license_plate.jpg")
|
||||
lp_np = np.array(lp_img)
|
||||
result3 = reader.readtext(lp_np)
|
||||
print(result3)
|
||||
2
app.py
2
app.py
@@ -16,4 +16,4 @@ def home():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="localhost", port=2222, debug=True)
|
||||
app.run(host="0.0.0.0", port=2222, debug=True)
|
||||
|
||||
@@ -2,9 +2,14 @@ from flask import Flask
|
||||
from flask_migrate import Migrate
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
# from authlib.integrations.flask_client import OAuth
|
||||
|
||||
# Memory for last_image
|
||||
last_image = BytesIO()
|
||||
|
||||
# Web Server
|
||||
app = Flask(__name__)
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data.sqlite"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from application import db
|
||||
import application
|
||||
from application.dashboard.models import AllowedPlate, LoggedItem
|
||||
from application.api.image_processing import process_image
|
||||
from datetime import datetime
|
||||
import asyncio
|
||||
import io
|
||||
|
||||
api_blueprint = Blueprint("api", __name__, template_folder="templates")
|
||||
|
||||
@@ -12,6 +14,8 @@ api_blueprint = Blueprint("api", __name__, template_folder="templates")
|
||||
@api_blueprint.route("/", methods=["POST"])
|
||||
def data():
|
||||
data = request.data
|
||||
application.last_image.seek(0)
|
||||
application.last_image = io.BytesIO(request.data)
|
||||
np = asyncio.run(process_image(image=data))
|
||||
|
||||
# Check if the found plate is allowed to exit
|
||||
|
||||
BIN
car_crop_pillow.jpg
Normal file
BIN
car_crop_pillow.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
BIN
license_plate.jpg
Normal file
BIN
license_plate.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
BIN
license_plate_detector.pt
Normal file
BIN
license_plate_detector.pt
Normal file
Binary file not shown.
BIN
yolov8n.pt
Normal file
BIN
yolov8n.pt
Normal file
Binary file not shown.
Reference in New Issue
Block a user