added test webcam
This commit is contained in:
@ -49,22 +49,22 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>🚦 Traffic Logger Dashboard</h1>
|
<h1>Monitoring Trafik</h1>
|
||||||
|
|
||||||
<div id="stats">
|
<div id="stats">
|
||||||
<div class="stat">🔢 Total Vehicle Log Entries: <span id="total-entries" class="loading">Loading...</span></div>
|
<div class="stat">🔢 Total Entri Log Kendaraan: <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">🚗 Kendaraan yang Saat Ini Berada di Antara Jalur: <span id="vehicle-zone" class="loading">Loading...</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>📋 Last 10 Vehicle Entries</h2>
|
<h2>📋 10 Entri Kendaraan Terakhir</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Vehicle ID</th>
|
<th>ID Kenderaan</th>
|
||||||
<th>Direction</th>
|
<th>Arah</th>
|
||||||
<th>Timestamp</th>
|
<th>Waktu</th>
|
||||||
<th>Speed (km/h)</th>
|
<th>Kecepatan (km/h)</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="log-table-body">
|
<tbody id="log-table-body">
|
||||||
|
|||||||
28
test_webcam.py
Normal file
28
test_webcam.py
Normal 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()
|
||||||
4
this.py
4
this.py
@ -104,14 +104,14 @@ while True:
|
|||||||
vehicle['t1'] = datetime.now()
|
vehicle['t1'] = datetime.now()
|
||||||
elif not vehicle['t2'] and cy >= speed_line_y2:
|
elif not vehicle['t2'] and cy >= speed_line_y2:
|
||||||
vehicle['t2'] = datetime.now()
|
vehicle['t2'] = datetime.now()
|
||||||
vehicle['direction'] = 'down'
|
vehicle['direction'] = 'bawah'
|
||||||
|
|
||||||
# Upward detection (added logic)
|
# Upward detection (added logic)
|
||||||
if not vehicle['t1'] and cy <= speed_line_y2:
|
if not vehicle['t1'] and cy <= speed_line_y2:
|
||||||
vehicle['t1'] = datetime.now()
|
vehicle['t1'] = datetime.now()
|
||||||
elif not vehicle['t2'] and cy <= speed_line_y1:
|
elif not vehicle['t2'] and cy <= speed_line_y1:
|
||||||
vehicle['t2'] = datetime.now()
|
vehicle['t2'] = datetime.now()
|
||||||
vehicle['direction'] = 'up'
|
vehicle['direction'] = 'atas'
|
||||||
|
|
||||||
# Speed calculation
|
# Speed calculation
|
||||||
if vehicle['t1'] and vehicle['t2'] and not vehicle['logged']:
|
if vehicle['t1'] and vehicle['t2'] and not vehicle['logged']:
|
||||||
|
|||||||
Reference in New Issue
Block a user