Fix: Zähllinie wird nicht mehr als Objekt erkannt
Problem: YOLO hat die gelbe Zähllinie als "Zahnbürste" erkannt Lösung: Zähllinie wird jetzt NACH der YOLO-Erkennung gezeichnet Änderungen: - YOLO-Erkennung läuft auf dem Original-Frame - Zähllinie wird erst danach als Overlay gezeichnet - Linie ist jetzt etwas dicker (3px statt 2px) für bessere Sichtbarkeit Resultat: Keine falschen Objekterkennungen mehr durch die Zähllinie 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
60
app.py
60
app.py
@@ -109,21 +109,7 @@ def detect_objects_from_webcam(line_data):
|
|||||||
# Resize the frame to (1020, 600)
|
# Resize the frame to (1020, 600)
|
||||||
frame = cv2.resize(frame, (1020, 600))
|
frame = cv2.resize(frame, (1020, 600))
|
||||||
|
|
||||||
# Draw counting line (dashed yellow line with black gaps)
|
# Run YOLOv8 tracking on the frame (BEFORE drawing the counting line!)
|
||||||
cv2.line(frame, line_start, line_end, (0, 255, 255), 2, cv2.LINE_AA)
|
|
||||||
# Draw dashed effect
|
|
||||||
line_length = int(np.sqrt((line_end[0] - line_start[0])**2 + (line_end[1] - line_start[1])**2))
|
|
||||||
dash_length = 20
|
|
||||||
for i in range(0, line_length, dash_length * 2):
|
|
||||||
t1 = i / line_length
|
|
||||||
t2 = min((i + dash_length) / line_length, 1.0)
|
|
||||||
x1 = int(line_start[0] + t1 * (line_end[0] - line_start[0]))
|
|
||||||
y1 = int(line_start[1] + t1 * (line_end[1] - line_start[1]))
|
|
||||||
x2 = int(line_start[0] + t2 * (line_end[0] - line_start[0]))
|
|
||||||
y2 = int(line_start[1] + t2 * (line_end[1] - line_start[1]))
|
|
||||||
cv2.line(frame, (x1, y1), (x2, y2), (0, 0, 0), 2)
|
|
||||||
|
|
||||||
# Run YOLOv8 tracking on the frame
|
|
||||||
results = model.track(frame, persist=True)
|
results = model.track(frame, persist=True)
|
||||||
|
|
||||||
if results[0].boxes is not None and results[0].boxes.id is not None:
|
if results[0].boxes is not None and results[0].boxes.id is not None:
|
||||||
@@ -171,6 +157,20 @@ def detect_objects_from_webcam(line_data):
|
|||||||
# Draw center point (yellow)
|
# Draw center point (yellow)
|
||||||
cv2.circle(frame, (center_x, center_y), 3, (0, 255, 255), -1)
|
cv2.circle(frame, (center_x, center_y), 3, (0, 255, 255), -1)
|
||||||
|
|
||||||
|
# Draw counting line AFTER YOLO detection (dashed yellow line)
|
||||||
|
cv2.line(frame, line_start, line_end, (0, 255, 255), 3, cv2.LINE_AA)
|
||||||
|
# Draw dashed effect
|
||||||
|
line_length = int(np.sqrt((line_end[0] - line_start[0])**2 + (line_end[1] - line_start[1])**2))
|
||||||
|
dash_length = 20
|
||||||
|
for i in range(0, line_length, dash_length * 2):
|
||||||
|
t1 = i / line_length
|
||||||
|
t2 = min((i + dash_length) / line_length, 1.0)
|
||||||
|
x1 = int(line_start[0] + t1 * (line_end[0] - line_start[0]))
|
||||||
|
y1 = int(line_start[1] + t1 * (line_end[1] - line_start[1]))
|
||||||
|
x2 = int(line_start[0] + t2 * (line_end[0] - line_start[0]))
|
||||||
|
y2 = int(line_start[1] + t2 * (line_end[1] - line_start[1]))
|
||||||
|
cv2.line(frame, (x1, y1), (x2, y2), (0, 0, 0), 3)
|
||||||
|
|
||||||
# Display vehicle count with type breakdown
|
# Display vehicle count with type breakdown
|
||||||
cv2.rectangle(frame, (10, 10), (350, 140), (0, 0, 0), -1)
|
cv2.rectangle(frame, (10, 10), (350, 140), (0, 0, 0), -1)
|
||||||
cv2.putText(frame, f'Gesamt: {vehicle_count}', (20, 35), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
|
cv2.putText(frame, f'Gesamt: {vehicle_count}', (20, 35), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
|
||||||
@@ -247,21 +247,7 @@ def detect_objects_from_video(video_path, line_data):
|
|||||||
# Resize the frame to (1020, 600)
|
# Resize the frame to (1020, 600)
|
||||||
frame = cv2.resize(frame, (1020, 600))
|
frame = cv2.resize(frame, (1020, 600))
|
||||||
|
|
||||||
# Draw counting line (dashed yellow line with black gaps)
|
# Run YOLOv8 tracking on the frame (BEFORE drawing the counting line!)
|
||||||
cv2.line(frame, line_start, line_end, (0, 255, 255), 2, cv2.LINE_AA)
|
|
||||||
# Draw dashed effect
|
|
||||||
line_length = int(np.sqrt((line_end[0] - line_start[0])**2 + (line_end[1] - line_start[1])**2))
|
|
||||||
dash_length = 20
|
|
||||||
for i in range(0, line_length, dash_length * 2):
|
|
||||||
t1 = i / line_length
|
|
||||||
t2 = min((i + dash_length) / line_length, 1.0)
|
|
||||||
x1 = int(line_start[0] + t1 * (line_end[0] - line_start[0]))
|
|
||||||
y1 = int(line_start[1] + t1 * (line_end[1] - line_start[1]))
|
|
||||||
x2 = int(line_start[0] + t2 * (line_end[0] - line_start[0]))
|
|
||||||
y2 = int(line_start[1] + t2 * (line_end[1] - line_start[1]))
|
|
||||||
cv2.line(frame, (x1, y1), (x2, y2), (0, 0, 0), 2)
|
|
||||||
|
|
||||||
# Run YOLOv8 tracking on the frame
|
|
||||||
results = model.track(frame, persist=True)
|
results = model.track(frame, persist=True)
|
||||||
|
|
||||||
if results[0].boxes is not None and results[0].boxes.id is not None:
|
if results[0].boxes is not None and results[0].boxes.id is not None:
|
||||||
@@ -309,6 +295,20 @@ def detect_objects_from_video(video_path, line_data):
|
|||||||
# Draw center point (yellow)
|
# Draw center point (yellow)
|
||||||
cv2.circle(frame, (center_x, center_y), 3, (0, 255, 255), -1)
|
cv2.circle(frame, (center_x, center_y), 3, (0, 255, 255), -1)
|
||||||
|
|
||||||
|
# Draw counting line AFTER YOLO detection (dashed yellow line)
|
||||||
|
cv2.line(frame, line_start, line_end, (0, 255, 255), 3, cv2.LINE_AA)
|
||||||
|
# Draw dashed effect
|
||||||
|
line_length = int(np.sqrt((line_end[0] - line_start[0])**2 + (line_end[1] - line_start[1])**2))
|
||||||
|
dash_length = 20
|
||||||
|
for i in range(0, line_length, dash_length * 2):
|
||||||
|
t1 = i / line_length
|
||||||
|
t2 = min((i + dash_length) / line_length, 1.0)
|
||||||
|
x1 = int(line_start[0] + t1 * (line_end[0] - line_start[0]))
|
||||||
|
y1 = int(line_start[1] + t1 * (line_end[1] - line_start[1]))
|
||||||
|
x2 = int(line_start[0] + t2 * (line_end[0] - line_start[0]))
|
||||||
|
y2 = int(line_start[1] + t2 * (line_end[1] - line_start[1]))
|
||||||
|
cv2.line(frame, (x1, y1), (x2, y2), (0, 0, 0), 3)
|
||||||
|
|
||||||
# Display vehicle count with type breakdown
|
# Display vehicle count with type breakdown
|
||||||
cv2.rectangle(frame, (10, 10), (350, 140), (0, 0, 0), -1)
|
cv2.rectangle(frame, (10, 10), (350, 140), (0, 0, 0), -1)
|
||||||
cv2.putText(frame, f'Gesamt: {vehicle_count}', (20, 35), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
|
cv2.putText(frame, f'Gesamt: {vehicle_count}', (20, 35), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user