Пример #1
0
 def _send_mail(self, file_stream: ImageStream):
     now = datetime.datetime.now()
     if (now - self._last_sent_mail_date).seconds < 120:
         return
 
     msg = MIMEMultipart()
     msg['Subject'] = "PiGuard ALERT!"
     msg['From'] = self._from
     msg['To'] = self._to
 
     text = MIMEText("Movement has been detected by PiGuard!")
     msg.attach(text)
     image = MIMEImage(file_stream.get_stream().read(), name="Alarm.jpg")
     msg.attach(image)
 
     s = smtplib.SMTP(self._smtp_addr, self._smtp_port)
     s.ehlo()
     s.starttls()
     s.ehlo()
     s.login(self._user_id, self._pass)
     s.sendmail(msg['From'], msg['To'], msg.as_string())
     s.quit()
 
     print("Warning mail sent!")
 
     self._last_sent_mail_date = now
Пример #2
0
    def _detect_motion(self, new_picture_stream: ImageStream):

        if self._last_picture_stream is None:
            self._last_picture_stream = new_picture_stream
            return False

        im1 = self._last_picture_stream.get_image()
        im2 = new_picture_stream.get_image()
        mean_diff = img_diff(im1, im2)

        motion_occurred = mean_diff > 10

        self._last_picture_stream = new_picture_stream

        if motion_occurred:
            print("motion status: Motion detected! ", mean_diff)
        else:
            print("motion status: Everything is quiet! ", mean_diff)

        return motion_occurred
Пример #3
0
    def _detect_motion(self, new_picture_stream: ImageStream):

        if self._last_picture_stream is None:
            self._last_picture_stream = new_picture_stream
            return False

        im1 = self._last_picture_stream.get_image()
        im2 = new_picture_stream.get_image()
        mean_diff = img_diff(im1, im2)

        motion_occurred = mean_diff > 10

        self._last_picture_stream = new_picture_stream

        if motion_occurred:
            print("motion status: Motion detected! ", mean_diff)
        else:
            print("motion status: Everything is quiet! ", mean_diff)

        return motion_occurred
Пример #4
0
def capture_picture() -> ImageStream:
    global camera
    stream = io.BytesIO()
    camera.capture(stream, format='jpeg')
    return ImageStream(stream)
Пример #5
0
 def save_image(self, image_stream: ImageStream, image_name: str):
     image_stream.get_image().save(self.pictures_dir + image_name)
Пример #6
0
 def save_image(self, image_stream: ImageStream, image_name: str):
     image_stream.get_image().save(self.pictures_dir + image_name)