-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameraCode.py
48 lines (35 loc) · 1.24 KB
/
cameraCode.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
## ------------- Camera Code ------------- ##
import cv2
from PyQt5.QtCore import QTimer
def camButtonStartClicked(self):
self.cameraCodeHelper()
self.lastFilter = 'Camera Active'
self.initializeSlider()
self.cap = cv2.VideoCapture(0)
self.timer = QTimer(self)
self.timer.timeout.connect(self.updateFrame)
self.timer.start(5)
def updateFrame(self):
ret, self.processedImage = self.cap.read()
if ret:
self.processedImage = cv2.flip(self.processedImage, 1)
if self.detectFaceCheckbox.isChecked():
if self.detectEye.isChecked():
self.actionFaceDetectionClicked(1)
else:
self.actionFaceDetectionClicked(0)
return
self.displayImage(2)
else:
self.processedImage = cv2.flip(self.processedImage, 1)
self.displayImage(2)
print('Failed to read from camera, Program will exit.')
self.camButtonStopClicked()
def camButtonStopClicked(self):
if self.cap:
self.cap.release()
self.timer.stop()
self.lastFilter = 'Camera Passive'
self.initializeSlider()
## ************* Camera Code End ************ ##
functions = (camButtonStartClicked, camButtonStopClicked, updateFrame)