-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfall.py
44 lines (32 loc) · 1.15 KB
/
fall.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
import cv2
import numpy as np
import pygame
cap = cv2.VideoCapture(0)
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load('fallaudio.mp3')
pygame.mixer.music.play()
fall = cv2.VideoCapture('fall.mpeg')
while cap.isOpened():
main_frame_found, main_frame = cap.read()
resized_frame = cv2.resize(main_frame, (720, 480))
fall_vid_found, fall_vid = fall.read()
fall_vid = cv2.resize(fall_vid, (720, 480))
_resized_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
copy_fall_vid = np.copy(fall_vid)
copy_fall_vid = cv2.cvtColor(copy_fall_vid, cv2.COLOR_BGR2RGB)
lower_green = np.array([0, 146, 52])
upper_green = np.array([200, 255, 203])
# lower_green = np.array([0, 40, 0])
# upper_green = np.array([80, 255, 125])
mask = cv2.inRange(copy_fall_vid, lower_green, upper_green)
masked_fall = np.copy(copy_fall_vid)
masked_fall[mask != 0] = [0, 0, 0]
_resized_frame[mask == 0] = [0, 0, 0]
final_vid = cv2.cvtColor(_resized_frame + masked_fall, cv2.COLOR_RGB2BGR)
cv2.imshow("Output", final_vid)
key = cv2.waitKey(1)
if key == ord('q'):
break
cap.release()
cv2.destroyAllWindows()