-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion_saliency.py
45 lines (37 loc) · 1.25 KB
/
motion_saliency.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
# USAGE
# python motion_saliency.py
# import the necessary packages
from imutils.video import VideoStream
import imutils
import time
import cv2
# initialize the motion saliency object and start the video stream
saliency = None
vs = VideoStream(src=1).start()
time.sleep(2.0)
# loop over frames from the video file stream
while True:
# grab the frame from the threaded video stream and resize it
# to 500px (to speedup processing)
frame = vs.read()
frame = imutils.resize(frame, width=500)
# if our saliency object is None, we need to instantiate it
if saliency is None:
saliency = cv2.saliency.MotionSaliencyBinWangApr2014_create()
saliency.setImagesize(frame.shape[1], frame.shape[0])
saliency.init()
# convert the input frame to grayscale and compute the saliency
# map based on the motion model
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
(success, saliencyMap) = saliency.computeSaliency(gray)
saliencyMap = (saliencyMap * 255).astype("uint8")
# display the image to our screen
cv2.imshow("Frame", frame)
cv2.imshow("Map", cv2.applyColorMap(saliencyMap, cv2.COLORMAP_JET))
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()