Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance when counting black pixels. #2

Merged
merged 1 commit into from
Jan 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions MotionDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,12 @@ def processImage(self, frame):

def somethingHasMoved(self):
nb=0 #Will hold the number of black pixels

for x in range(self.height): #Iterate the hole image
for y in range(self.width):
if self.res[x,y] == 0.0: #If the pixel is black keep it
nb += 1
avg = (nb*100.0)/self.nb_pixels #Calculate the average of black pixel in the image

if avg > self.threshold:#If over the ceiling trigger the alarm
return True
min_threshold = (self.nb_pixels/100) * self.threshold #Number of pixels for current threshold
nb = self.nb_pixels - cv.CountNonZero(self.res)
if (nb) > min_threshold:
return True
else:
return False
return False

if __name__=="__main__":
detect = MotionDetectorInstantaneous(doRecord=True)
Expand Down