Skip to content

Commit ec3b8bd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4df87fc commit ec3b8bd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

computer_vision/motion_detection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cv2
22

3+
34
def detect_motion(video_source=0):
45
cap = cv2.VideoCapture(video_source)
56
ret, frame1 = cap.read()
@@ -8,7 +9,7 @@ def detect_motion(video_source=0):
89
while cap.isOpened():
910
diff = cv2.absdiff(frame1, frame2)
1011
gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
11-
blur = cv2.GaussianBlur(gray, (5,5), 0)
12+
blur = cv2.GaussianBlur(gray, (5, 5), 0)
1213
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
1314
dilated = cv2.dilate(thresh, None, iterations=3)
1415
contours, _ = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
@@ -17,7 +18,7 @@ def detect_motion(video_source=0):
1718
if cv2.contourArea(contour) < 1000:
1819
continue
1920
(x, y, w, h) = cv2.boundingRect(contour)
20-
cv2.rectangle(frame1, (x, y), (x+w, y+h), (0, 255, 0), 2)
21+
cv2.rectangle(frame1, (x, y), (x + w, y + h), (0, 255, 0), 2)
2122

2223
cv2.imshow("Motion Detection", frame1)
2324
frame1 = frame2

0 commit comments

Comments
 (0)