-
Notifications
You must be signed in to change notification settings - Fork 1
/
motion_Detect.py
60 lines (44 loc) · 1.24 KB
/
motion_Detect.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
57
58
59
60
#!/usr/bin/python3
import cv2
import pyttsx3
import time
import numpy as np
def warning():
engine = pyttsx3.init()
engine.say("your motion is detected")
engine.runAndWait()
def create_image_diff(x,y,z):
img1_df = cv2.absdiff(x,y)
img2_df = cv2.absdiff(y,z)
img3 = cv2.bitwise_and(img1_df,img2_df)
return img3
# starting web cam
cap = cv2.VideoCapture(0)
tp1 = cap.read()[1]
tp2 = cap.read()[1]
tp3 = cap.read()[1]
#converting to greyscale
gray1 = cv2.cvtColor(tp1,cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(tp2,cv2.COLOR_BGR2GRAY)
gray3 = cv2.cvtColor(tp3,cv2.COLOR_BGR2GRAY)
blank_img=np.zeros((480,640))
#gray4 = cv2.cvtColor(blank_img,cv2.COLOR_BGR2GRAY)
while True:
#calling function
new_img = create_image_diff(gray1,gray2,gray3)
print (new_img.shape)
cv2.imshow('wind1',new_img)
#capture new img
status,frame = cap.read()
cv2.imshow('new',frame)
#exchange img
a = gray1 = gray2
b = gray2 = gray3
c = gray3 = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#if new_img == blank_img.all:
# warning()
# print ("asa")
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyeAllWindows()
cap.release()