-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvideoLaneDetection.py
More file actions
44 lines (32 loc) · 894 Bytes
/
Copy pathvideoLaneDetection.py
File metadata and controls
44 lines (32 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import cv2
import pafy
from ultrafastLaneDetector import UltrafastLaneDetector, ModelType
model_path = "models/tusimple_18.pth"
model_type = ModelType.TUSIMPLE
use_gpu = False
# Initialize video
# cap = cv2.VideoCapture("video.mp4")
videoUrl = 'https://youtu.be/2CIxM7x-Clc'
videoPafy = pafy.new(videoUrl)
print(videoPafy.streams)
cap = cv2.VideoCapture(videoPafy.streams[-1].url)
# Initialize lane detection model
lane_detector = UltrafastLaneDetector(model_path, model_type, use_gpu)
cv2.namedWindow("Detected lanes", cv2.WINDOW_NORMAL)
while cap.isOpened():
try:
# Read frame from the video
ret, frame = cap.read()
except:
continue
if ret:
# Detect the lanes
output_img = lane_detector.detect_lanes(frame)
cv2.imshow("Detected lanes", output_img)
else:
break
# Press key q to stop
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()