-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfirst_tut.py
49 lines (31 loc) · 1.07 KB
/
first_tut.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
import cv2
# img = cv2.imread('test_images/lena.jpg',-1)
# cv2.imshow('image',img)
# k = cv2.waitKey(0)
# if k == 27:
# cv2.destroyAllWindows()
# elif k == ord('s'):
# cv2.imwrite('test_images/lena_copy_2.png' , img)
# cv2.destroyAllWindows()
########## Video Capture ###########
## If we want to load our video file we can do that by giving
# name of file in video capture.
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID') # need to save video
out = cv2.VideoWriter('output.avi',fourcc , 20 , (640,480)) # save live video
## isOpened is useful for to check if cap capture something.
while(cap.isOpened()):
ret , frame = cap.read()
if ret == True:
gray = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
cv2.imshow('manthan' , gray)
out.write(frame)
print(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # Frame height
print(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # Frame width
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()