-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilters
More file actions
71 lines (61 loc) · 2.06 KB
/
Filters
File metadata and controls
71 lines (61 loc) · 2.06 KB
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
68
69
70
71
import cv2
import glob
import math
class CFEVideoConf(object):
# Standard Video Dimensions Sizes
STD_DIMENSIONS = {
"360p": (480, 360),
"480p": (640, 480),
"720p": (1280, 720),
"1080p": (1920, 1080),
"4k": (3840, 2160),
}
# Video Encoding, might require additional installs
# Types of Codes: http://www.fourcc.org/codecs.php
VIDEO_TYPE = {
'avi': cv2.VideoWriter_fourcc(*'XVID'),
#'mp4': cv2.VideoWriter_fourcc(*'H264'),
'mp4': cv2.VideoWriter_fourcc(*'XVID'),
}
width = 640
height = 480
dims = (640, 480)
capture = None
video_type = None
def __init__(self, capture, filepath, res="480p", *args, **kwargs):
self.capture = capture
self.filepath = filepath
self.width, self.height = self.get_dims(res=res)
#self.video_type = self.get_video_type()
# Set resolution for the video capture
# Function adapted from https://kirr.co/0l6qmh
def change_res(self, width, height):
self.capture.set(3, width)
self.capture.set(4, height)
def get_dims(self, res='480p'):
width, height = self.STD_DIMENSIONS['480p']
if res in self.STD_DIMENSIONS:
width, height = self.STD_DIMENSIONS[res]
self.change_res(width, height)
self.dims = (width, height)
return width, height
'''def get_video_type(self):
filename, ext = os.path.splitext(self.filepath)
if ext in self.VIDEO_TYPE:
return self.VIDEO_TYPE[ext]
return self.VIDEO_TYPE['avi']'''
cap = cv2.VideoCapture(0)
frames_per_seconds = 20
save_path = 'saved-media/filter.mp4'
config=CFEVideoConf(cap,filepath=save_path,res='480p')
def apply_invert(frame): #inverting the image
return cv2.bitwise_not(frame)
while(True):
ret,frame=cap.read()
invert = apply_invert(frame)
#cv2.imshow('Normal Camera',frame)
cv2.imshow('Inverted Image',invert)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()