-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path#21_read_video.py
67 lines (46 loc) · 1.56 KB
/
#21_read_video.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import cv2
# ? can be used with:
# 1- webcam
# 2- local video File
# 3- ip camera
# ** 1- webcam **
# video = cv2.VideoCapture(0)
# while True:
# grabbed, frame = video.read()
# frame = cv2.resize(frame, (800, 500))
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# cv2.imshow('video', frame)
# video.release()
# cv2.destroyAllWindows()
# * ============================================
# ** 2- local video File **
video = cv2.VideoCapture("images/road.webm")
# Video Properties : #? CAP_PROP_*
#!READ THIS:
# https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-get
print('============================================')
fps = int(video.get(cv2.CAP_PROP_FPS))
frames_num = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
w = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(fps, "FPS")
print(frames_num, "Frames")
print("Width:", w)
print("Height:", h)
print('Duration: {} seconds'.format(frames_num // fps))
print('============================================')
# ? another way
while video.isOpened():
graped, frame = video.read()
key = cv2.waitKey(1)
if (key & 0xFF) == ord('q') or not graped:
break
if (key & 0xFF) == ord('0'):
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
cv2.imshow("video", frame)
cv2.waitKey(fps) # ? 30 FPS ==> 1 frame per 0.033 second ==> 30 ms
# * ============================================
# ** 3- ip camera **
# video = cv2.VideoCapture(
# "http://217.126.89.102:8010/axis-cgi/mjpg/video.cgi")