-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_3.py
46 lines (34 loc) · 1.06 KB
/
cv_3.py
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
45
46
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Open the video file
# cap = cv2.VideoCapture(r"/home/candy/Desktop/first_selfie.jpg")
cap = cv2.VideoCapture(0)
while cap.isOpened():
# Read a frame from the video
ret, frame = cap.read()
if not ret:
break
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
h_min = 16
h_max = 35
s_min = 79
s_max = 255
v_min = 101
v_max = 255
lower = np.array([h_min, s_min, v_min])
upper = np.array([h_max, s_max, v_max])
mask = cv2.inRange(hsv, lower, upper)
result = cv2.bitwise_and(frame, frame, mask = mask)
# lane_image = np.copy(frame)
# Display the processed frame
cv2.imshow('Video', frame)
cv2.imshow('mask', mask)
cv2.imshow('yellow', result)
# Introduce a delay to play the video at normal speed
# Set the argument to 1 to introduce a small delay (approximately the frame rate)
if cv2.waitKey(4) & 0xFF == ord('q'):
break
# Release the video capture and close all windows
cap.release()
cv2.destroyAllWindows()