avoid divide by zero

This commit is contained in:
Blake Blackshear 2021-11-17 07:29:23 -06:00
parent 9b23ff597c
commit 543a8a1712

View File

@ -40,10 +40,12 @@ class MotionDetector:
# Improve contrast
minval = np.percentile(resized_frame, 4)
maxval = np.percentile(resized_frame, 96)
# don't adjust if the image is a single color
if minval < maxval:
resized_frame = np.clip(resized_frame, minval, maxval)
resized_frame = (((resized_frame - minval) / (maxval - minval)) * 255).astype(
np.uint8
)
resized_frame = (
((resized_frame - minval) / (maxval - minval)) * 255
).astype(np.uint8)
# mask frame
resized_frame[self.mask] = [255]