We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
0 parents commit aa1a0fdCopy full SHA for aa1a0fd
alert.wav
331 KB
main.py
@@ -0,0 +1,22 @@
1
+import cv2
2
+import winsound
3
+cam = cv2.VideoCapture(1)
4
+while cam.isOpened():
5
+ ret, frame1 = cam.read()
6
+ ret, frame2 = cam.read()
7
+ diff = cv2.absdiff(frame1, frame2)
8
+ gray = cv2.cvtColor(diff, cv2.COLOR_RGB2GRAY)
9
+ blur = cv2.GaussianBlur(gray, (5, 5), 0)
10
+ _, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
11
+ dilated = cv2.dilate(thresh, None, iterations=3)
12
+ contours, _ = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
13
+ # cv2.drawContours(frame1, contours, -1, (0, 255, 0), 2)
14
+ for c in contours:
15
+ if cv2.contourArea(c) < 5000:
16
+ continue
17
+ x, y, w, h = cv2.boundingRect(c)
18
+ cv2.rectangle(frame1, (x, y), (x+w, y+h), (0, 255, 0), 2)
19
+ winsound.PlaySound('alert.wav', winsound.SND_ASYNC)
20
+ if cv2.waitKey(10) == ord('q'):
21
+ break
22
+ cv2.imshow('Granny Cam', frame1)
0 commit comments