added test webcam

This commit is contained in:
kicap
2025-07-16 19:36:56 +08:00
parent aa90d3a455
commit 40a4cbaafc
3 changed files with 38 additions and 10 deletions

View File

@ -49,22 +49,22 @@
</style>
</head>
<body>
<h1>🚦 Traffic Logger Dashboard</h1>
<h1>Monitoring Trafik</h1>
<div id="stats">
<div class="stat">🔢 Total Vehicle Log Entries: <span id="total-entries" class="loading">Loading...</span></div>
<div class="stat">🚗 Vehicles Currently Between Lines: <span id="vehicle-zone" class="loading">Loading...</span></div>
<div class="stat">🔢 Total Entri Log Kendaraan: <span id="total-entries" class="loading">Loading...</span></div>
<div class="stat">🚗 Kendaraan yang Saat Ini Berada di Antara Jalur: <span id="vehicle-zone" class="loading">Loading...</span></div>
</div>
<h2>📋 Last 10 Vehicle Entries</h2>
<h2>📋 10 Entri Kendaraan Terakhir</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Vehicle ID</th>
<th>Direction</th>
<th>Timestamp</th>
<th>Speed (km/h)</th>
<th>ID Kenderaan</th>
<th>Arah</th>
<th>Waktu</th>
<th>Kecepatan (km/h)</th>
</tr>
</thead>
<tbody id="log-table-body">

28
test_webcam.py Normal file
View File

@ -0,0 +1,28 @@
import cv2
# Open the default camera (0)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open webcam.")
exit()
print("Press 'q' to quit.")
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Display the resulting frame
cv2.imshow('Webcam Test', frame)
# Press 'q' to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release everything when done
cap.release()
cv2.destroyAllWindows()

View File

@ -104,14 +104,14 @@ while True:
vehicle['t1'] = datetime.now()
elif not vehicle['t2'] and cy >= speed_line_y2:
vehicle['t2'] = datetime.now()
vehicle['direction'] = 'down'
vehicle['direction'] = 'bawah'
# Upward detection (added logic)
if not vehicle['t1'] and cy <= speed_line_y2:
vehicle['t1'] = datetime.now()
elif not vehicle['t2'] and cy <= speed_line_y1:
vehicle['t2'] = datetime.now()
vehicle['direction'] = 'up'
vehicle['direction'] = 'atas'
# Speed calculation
if vehicle['t1'] and vehicle['t2'] and not vehicle['logged']: