Capstone Project Code
Capstone Project Code
import time
import numpy as np
# Video capture
cap1 = cv2.VideoCapture('traffic_video.mp4')
cap2 = cv2.VideoCapture('traffic_video2.mp4')
cap3 = cv2.VideoCapture('traffic_video3.mp4')
cap4 = cv2.VideoCapture('traffic_video1.mp4')
# Video dimensions
frame_width = int(cap1.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap1.get(cv2.CAP_PROP_FRAME_HEIGHT))
while True:
# Read frames from all four videos
ret1, frame1 = cap1.read()
ret2, frame2 = cap2.read()
ret3, frame3 = cap3.read()
ret4, frame4 = cap4.read()
# Resize frames
frame1 = cv2.resize(frame1, (frame_width, frame_height))
frame2 = cv2.resize(frame2, (frame_width, frame_height))
frame3 = cv2.resize(frame3, (frame_width, frame_height))
frame4 = cv2.resize(frame4, (frame_width, frame_height))
# Check if the allotted time for the current signal has elapsed
elapsed_time = time.time() - start_time
if elapsed_time >= total_time:
start_time = time.time() # Reset start time
# Log signal times for the next cycle
print("Signal Times for Next Cycle:")
for idx, time_allotted in enumerate(signal_times, start=1):
print(f"Quadrant {idx}: Green Time: {green_time} sec, Yellow Time:
{yellow_time} sec")
print("")