From 40a4cbaafc57ccd553c956947bb7d5c31ffc1237 Mon Sep 17 00:00:00 2001 From: kicap Date: Wed, 16 Jul 2025 19:36:56 +0800 Subject: [PATCH] added test webcam --- templates/index.html | 16 ++++++++-------- test_webcam.py | 28 ++++++++++++++++++++++++++++ this.py | 4 ++-- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 test_webcam.py diff --git a/templates/index.html b/templates/index.html index 3d87974..023f6d9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -49,22 +49,22 @@ -

🚦 Traffic Logger Dashboard

+

Monitoring Trafik

-
🔢 Total Vehicle Log Entries: Loading...
-
🚗 Vehicles Currently Between Lines: Loading...
+
🔢 Total Entri Log Kendaraan: Loading...
+
🚗 Kendaraan yang Saat Ini Berada di Antara Jalur: Loading...
-

📋 Last 10 Vehicle Entries

+

📋 10 Entri Kendaraan Terakhir

- - - - + + + + diff --git a/test_webcam.py b/test_webcam.py new file mode 100644 index 0000000..3a2dfde --- /dev/null +++ b/test_webcam.py @@ -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() diff --git a/this.py b/this.py index 24b05a5..092c71a 100644 --- a/this.py +++ b/this.py @@ -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']:
IDVehicle IDDirectionTimestampSpeed (km/h)ID KenderaanArahWaktuKecepatan (km/h)