Update app.py
Browse files
app.py
CHANGED
@@ -11,30 +11,40 @@ dino_model = pipeline("zero-shot-object-detection", model="IDEA-Research/groundi
|
|
11 |
|
12 |
# YOLOv8-Erkennung
|
13 |
def detect_with_yolo(image: Image.Image):
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Grounding DINO-Erkennung
|
18 |
def detect_with_grounding_dino(image: Image.Image, prompt=["license plate.", "number plate.", "car plate.", "vehicle registration plate."]):
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
score = result["score"]
|
30 |
-
label = "license plate"
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
|
|
|
|
38 |
|
39 |
# Verarbeitung der Bilder
|
40 |
def process_image(image):
|
|
|
11 |
|
12 |
# YOLOv8-Erkennung
|
13 |
def detect_with_yolo(image: Image.Image):
|
14 |
+
try:
|
15 |
+
results = yolo_model(np.array(image))[0]
|
16 |
+
return Image.fromarray(results.plot())
|
17 |
+
except Exception as e:
|
18 |
+
logging.error(f"YOLOv8 Fehler: {e}")
|
19 |
+
return image
|
20 |
|
21 |
# Grounding DINO-Erkennung
|
22 |
def detect_with_grounding_dino(image: Image.Image, prompt=["license plate.", "number plate.", "car plate.", "vehicle registration plate."]):
|
23 |
+
try:
|
24 |
+
results = dino_model(image, candidate_labels=prompt)
|
25 |
+
image_np = np.array(image).copy()
|
26 |
|
27 |
+
if not results:
|
28 |
+
return image # Keine Erkennung = Originalbild
|
29 |
|
30 |
+
results = [result for result in results if result["score"] > 0.4]
|
31 |
|
32 |
+
if not results:
|
33 |
+
return image
|
|
|
|
|
34 |
|
35 |
+
for result in results:
|
36 |
+
box = result["box"]
|
37 |
+
score = result["score"]
|
38 |
+
label = "license plate"
|
39 |
+
x1, y1, x2, y2 = int(box["xmin"]), int(box["ymin"]), int(box["xmax"]), int(box["ymax"])
|
40 |
+
image_np = cv2.rectangle(image_np, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
41 |
+
image_np = cv2.putText(image_np, f"{label} ({score:.2f})", (x1, y1 - 10),
|
42 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)
|
43 |
+
return Image.fromarray(image_np)
|
44 |
|
45 |
+
except Exception as e:
|
46 |
+
logging.error(f"Grounding DINO Fehler: {e}")
|
47 |
+
return image
|
48 |
|
49 |
# Verarbeitung der Bilder
|
50 |
def process_image(image):
|