def MotionImage(self, threshold=200):
""" Returns the image from the sum of the next window
"""
# Initialise image
img = np.zeros((self.w, self.h), dtype=np.uint8)
# Get first frame of the window
A = cv2.cvtColor(self.window[0], cv2.COLOR_BGR2GRAY)
# Iterate over the rest of the window
for i in range(1, self.length):
# Load next frame
B = cv2.cvtColor(self.window[i], cv2.COLOR_BGR2GRAY)
# Image subtraction
dif = cv2.absdiff(B, A)
# Add to Motion Image
img = cv2.add(img, dif)
# Store the last grayscale frame
A = B
r, img = cv2.threshold(img, threshold, 255, cv2.THRESH_BINARY)
# Try and get the next video frame
try:
self.window.append(self.read())
self.window.popleft()
except:
self.hasData = False
return img
评论列表
文章目录