Esempio n. 1
0
 def start(self,sens, method, mail, sound, notif):
     self.online = False
     print "staring..."
     iterator = 0
     count = 0
     while True:
         success, image = self.video.read()
         if not success:
             continue
         iterator += 1
         gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
         if method == 'face':
             faceCascade = cv2.CascadeClassifier("faceDetect.xml")
         elif method == 'ubody':
             faceCascade = cv2.CascadeClassifier("haarcascade_upperbody.xml")
         elif method == 'fbody':
             faceCascade = cv2.CascadeClassifier("haarcascade_fullbody.xml")
         faces = faceCascade.detectMultiScale(
             gray,
             scaleFactor=1.1,
             minNeighbors=5,
             flags=cv2.cv.CV_HAAR_SCALE_IMAGE
              )
         if type(faces) is not tuple:
             count+=1
         if self.online:
             print "Stopped by User"
             return
         if count == sens:
             print "Face Detected!"
             img = self.get_frame(False)
             if notif:
                 try:
                     print "sending Image to mail....."
                     mailer.send_notification(self.config)
                 except:
                     print "ERROR"
             if mail:
                 try:
                     print "sending Image to mail....."
                     mailer.sendMessege(img, self.config)
                     return
                 except:
                     print "ERROR"
             if sound:
                 winsound.PlaySound(self.config.get('Other')['alarm'], winsound.SND_FILENAME)
             return  
         if iterator==12:
             iterator=0
             count=0
Esempio n. 2
0
    def start(self, sens, method, mail, sound, notif):
        self.online = False
        logging.info('Active security started at ' +
                     str(datetime.datetime.now()))
        iterator = 0
        repeated = 0
        sequence_capture = False
        self.first_captured = None
        while True:
            success, image = self.video.read()
            if not success:
                continue
            iterator += 1
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            if method == 'face':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/faceDetect.xml")
            elif method == 'ubody':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/haarcascade_upperbody.xml")
            elif method == 'fbody':
                faceCascade = cv2.CascadeClassifier(
                    "haarcascade/haarcascade_fullbody.xml")
            elif method == 'move':
                if self.first_captured is None:
                    self.first_captured = gray
                frameDelta = cv2.absdiff(self.first_captured, gray)
                self.first_captured = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                thresh = cv2.threshold(frameDelta, 25, 255,
                                       cv2.THRESH_BINARY)[1]
                thresh = cv2.dilate(thresh, None, iterations=2)
                (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
                                             cv2.CHAIN_APPROX_SIMPLE)
                for c in cnts:
                    if cv2.contourArea(c) < int(
                            self.config.get('Video')['min_movement_object']):
                        continue
                    repeated += 1
                    break
            if method == 'ubody' or method == 'fbody' or method == 'face':
                #TODO export arguments to config file
                faces = faceCascade.detectMultiScale(gray,
                                                     scaleFactor=1.1,
                                                     minNeighbors=5,
                                                     flags=0)
                if type(faces) is not tuple:
                    if sequence_capture:
                        repeated += 1
                    sequence_capture = True
                else:
                    sequence_capture = False
                    repeated = 0
            if self.online:
                logging.info('Active security Stopped by user at ' +
                             str(datetime.datetime.now()))
                self.first_captured = None
                return
            if repeated == (6 - sens):
                logging.info('Figure has been Detected at ' +
                             str(datetime.datetime.now()))
                ret, jpeg = cv2.imencode('.jpg', image)
                img = jpeg.tostring()
                if notif:
                    try:
                        logging.info('Sending notification  ' +
                                     str(datetime.datetime.now()))
                        if 'bxc' in self.config.get("Notifications"):
                            mailer.send_notification(self.config)
                        if self.notification.user:
                            self.notification.send_notification()
                    except:
                        logging.warn('Error sending notification  ' +
                                     str(datetime.datetime.now()))
                if sound:
                    pygame.mixer.music.load(self.config.get('Sound')['alarm'])
                    pygame.mixer.music.play()
                    while pygame.mixer.music.get_busy() == True:
                        continue

                if mail:
                    try:
                        logging.info('Sending email ' +
                                     str(datetime.datetime.now()))
                        mailer.sendMessege(img, self.config)
                    except:
                        logging.info('Error Sending Mail ' +
                                     str(datetime.datetime.now()))
                self.first_captured = None
                return
            if iterator == 10:
                iterator = 0
                repeated = 0
Esempio n. 3
0
    def start(self,sens, method, mail, sound, notif):
        self.online = False
        logging.info('Active security started at ' + str(datetime.datetime.now()))
        iterator = 0
        repeated = 0
        sequence_capture = False
        self.first_captured = None
        while True:
            success, image = self.video.read()
            if not success:
                continue
            iterator += 1
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            if method == 'face':
                faceCascade = cv2.CascadeClassifier("haarcascade/faceDetect.xml")
            elif method == 'ubody':
                faceCascade = cv2.CascadeClassifier("haarcascade/haarcascade_upperbody.xml")
            elif method == 'fbody':
                faceCascade = cv2.CascadeClassifier("haarcascade/haarcascade_fullbody.xml")
            elif method == 'move':
                if self.first_captured is None:
                    self.first_captured = gray
                frameDelta = cv2.absdiff(self.first_captured, gray)
                self.first_captured = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                thresh = cv2.threshold(frameDelta, 25, 255, cv2.THRESH_BINARY)[1]
                thresh = cv2.dilate(thresh, None, iterations=2)
                (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
                for c in cnts:
                    if cv2.contourArea(c) < int(self.config.get('Video')['min_movement_object']):
                        continue
                    repeated += 1
                    break
            if method == 'ubody' or method == 'fbody' or method == 'face':
                #TODO export arguments to config file
                faces = faceCascade.detectMultiScale(
                    gray,
                    scaleFactor=1.1,
                    minNeighbors=5,
                    flags=0)
                if type(faces) is not tuple:
                    if sequence_capture:
                        repeated += 1
                    sequence_capture = True
                else:
                    sequence_capture = False
                    repeated = 0
            if self.online:
                logging.info('Active security Stopped by user at ' + str(datetime.datetime.now()))
                self.first_captured = None
                return
            if repeated == (6 - sens):
                logging.info('Figure has been Detected at ' + str(datetime.datetime.now()))
                ret, jpeg = cv2.imencode('.jpg', image)
                img = jpeg.tostring()
                if notif:
                    try:
                        logging.info('Sending notification  ' + str(datetime.datetime.now()))
                        mailer.send_notification(self.config)
                    except:
                        logging.warn('Error sending notification  ' + str(datetime.datetime.now()))
                if sound: 
                    pygame.mixer.music.load(self.config.get('Sound')['alarm'])
                    pygame.mixer.music.play()
                    while pygame.mixer.music.get_busy() == True:
                        continue

                if mail:
                    try:
                        logging.info('Sending email ' + str(datetime.datetime.now()))
                        mailer.sendMessege(img, self.config)
                    except:
                        logging.info('Error Sending Mail ' + str(datetime.datetime.now()))
                self.first_captured = None
                return
            if iterator == 10:
                iterator = 0
                repeated = 0