-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (40 loc) · 1.42 KB
/
main.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
import cv2
import numpy as np
from detection import DetectionClass
from masking import BackgroundMasking
from contours_detection import contours
# class for perspective transform main py
class MainClass:
def __init__(self):
# detection
self.c = DetectionClass()
self.coordinates = self.c.detect_and_extract()
self.c.cap.release()
# background masker
self.bgmask = BackgroundMasking()
# new video
self.video = cv2.VideoCapture(0)
def main_loop(self):
while True:
_, frame = self.video.read()
frame = cv2.resize(frame, (640, 480))
# source and destination
source = np.float32(self.coordinates)
dst = np.float32([[0, 0], [0, 480], [640, 480], [640, 0]])
# perspective transform
matrx = cv2.getPerspectiveTransform(source, dst)
perspective_frame = cv2.warpPerspective(frame, matrx, (640, 480))
# bg mask
bgframe = self.bgmask.background_subtracted(frame=perspective_frame)
# contours image
point = contours(bgframe, perspective_frame)
if point:
print(point)
cv2.imshow("frame", perspective_frame)
if cv2.waitKey(1) == 27:
break
self.video.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
m = MainClass()
m.main_loop()