-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotion_only.py
More file actions
27 lines (23 loc) · 773 Bytes
/
motion_only.py
File metadata and controls
27 lines (23 loc) · 773 Bytes
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
import cv2
from cv2utils.args import make_parser
from cv2utils.camera import make_camera_with_args
def prepare(frame):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = cv2.GaussianBlur(frame, (21, 21), 0)
return frame
def preprocess(frames, raw):
diff = cv2.absdiff(frames[0], frames[1])
diff[diff <= thresh] = 0
diff[diff > thresh] = 1
return -cv2.cvtColor(diff, cv2.COLOR_GRAY2BGR) * raw
parser = make_parser()
parser.add_argument(
"-t",
"--threshold",
type=int,
default=15,
help="The threshold for the glow effect on motion",
)
camera, args = make_camera_with_args(parser=parser, log=False, fps=15, res=(1280, 720))
thresh = args.threshold
camera.stream(prepare=prepare, preprocess=preprocess, frames_stored=2)