-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal Project!
More file actions
122 lines (91 loc) · 3.32 KB
/
Final Project!
File metadata and controls
122 lines (91 loc) · 3.32 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from kivy.app import App
from kivy.uix.camera import Camera
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
import cv2
import glob
import math
class CFEVideoConf(object):
STD_DIMENSIONS = {
"360p": (480, 360),
"480p": (640, 480),
"720p": (1280, 720),
"1080p": (1920, 1080),
"4k": (3840, 2160),
}
VIDEO_TYPE = {
'avi': cv2.VideoWriter_fourcc(*'XVID'),
'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)
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
class CameraApp(App):
def build(self):
'''
:return:
'''
self.camera_obj = Camera()
self.camera_obj.resolution = (800,800)
#button_for_capturing_image
button1 = Button(text = "Capture!",size_hint= (.5, .2),pos_hint = {'x':.25, 'y':.25})
button1.bind(on_press = self.take_image)
#button_for_scanning_qr_code
button2 = Button(text = "QR code scan!",size_hint= (.5, .2),pos_hint = {'x':.25, 'y':.25})
button2.bind(on_press = self.QR_code)
#button_for_applying_filter
button3 = Button(text = "Apply filter!",size_hint= (.5, .2),pos_hint = {'x':.25, 'y':.25})
button3.bind(on_press = self.apply_filter)
#Layout
layout = BoxLayout()
layout.add_widget(self.camera_obj)
layout.add_widget(button1)
layout.add_widget(button2)
layout.add_widget(button3)
return layout
def take_image(self, *args):
print("Picture is being captured!")
self.camera_obj.export_to_png("./selfie.png")
def QR_code(self, *args):
vid = cv2.VideoCapture(0)
qrCodeDetector = cv2.QRCodeDetector()
while True:
ret,frame=vid.read()
cv2.imshow('frame',frame)
decodedText, points, _ = qrCodeDetector.detectAndDecode(frame)
if points is not None:
print(decodedText)
else:
print("QR code not detected")
if cv2.waitKey(1) & 0xFF==ord('q'):
break
vid.release()
def apply_filter(self, *args):
cap = cv2.VideoCapture(0)
frames_per_seconds = 20
save_path = 'saved-media/filter.mp4'
config=CFEVideoConf(cap,filepath=save_path,res='480p')
while(True):
ret,frame=cap.read()
cv2.imshow('Inverted Color',cv2.bitwise_not(frame))
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
if __name__=='__main__':
CameraApp().run()