Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement speed into this? #7

Open
FaizelK opened this issue Dec 6, 2023 · 0 comments
Open

How to implement speed into this? #7

FaizelK opened this issue Dec 6, 2023 · 0 comments

Comments

@FaizelK
Copy link

FaizelK commented Dec 6, 2023

I would like to add speed, so I the "webcam or video" is seen as the driving vehicle.

I know that speed is distance over time. So i get the frames per second keep record of the distance travelled per frame, i should be able to estimate speed.

def calculate_fps(cap):
count_frames = 0
start_time = time.time()

while True:
    # Read the next frame from the video file
    ret, frame = cap.read()
    count_frames += 1

    if ret:
        elapsed_time = time.time() - start_time
        current_fps = count_frames / elapsed_time
        break
    else:
        break

return current_fps

while cap.isOpened():
try:
ret, frame = cap.read()
except:
continue

if ret:	

	# Detect the lanes
	output_img = lane_detector.detect_lanes(frame)

	fps = calculate_fps(cap)

	# Calculate speed
	ym_per_pix = 0.2  # meters per pixel
	speed = np.sum(lane_detector.distances[-int(fps):], axis=0) * ym_per_pix * fps * 3.6 # km/h

	average_speed = round(np.mean(speed))
	print('Average Speed:', average_speed, 'km/h')

I know i have to initial and keep record of distances variable inside UltrafastLaneDetector class. How can i go about doing this? is this the right approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant