Esempio n. 1
0
    def depth_callback(self, dev, data, timestamp):
        # add the data to our running average
        self.running_avg.add(data)

        if self.mode == 'uncalibrated':
            self.frame_count += 1
            if self.frame_count == self.dsum_buffer.size():
                self.set_mode('nomotion')
        else:
            mean_array = self.running_avg.mean()

            # difference from sum of buffer
            dsum = mean_array.sum()
            self.dsum_buffer.add(dsum)
            delta = self.dsum_buffer.std_delta(dsum)

            # frame will count as a motion frame
            if delta > self.change_threshold:
                self.motion_frames += 1
                if (self.motion_frames == self.min_report_event and
                    self.mode == 'nomotion'):
                    self.set_mode('motion')
                    alert = Alert.objects.create(event_type='motion')
                    self._snapshot = alert.id
            else:
                # don't let motion_frames drop below 0
                self.motion_frames = max(self.motion_frames-1, 0)
                if self.motion_frames == 0 and self.mode == 'motion':
                    self.set_mode('nomotion')
                    # could log how long the event was and its intensity here

            if self.debug:
                cv.ShowImage('Depth', simplify_cv(mean_array.astype(numpy.uint16)))
                cv.WaitKey(1)
Esempio n. 2
0
    def video_callback(self, dev, data, timestamp):
        if self.nightvision:
            cv_data = simplify_cv(data)
        else:
            cv_data = video_cv(data)

        if self.debug:
            cv.ShowImage('Video', cv_data)


        if (self._last_img + self.snapshot_secs < time.time() or
            self._snapshot):
            cv.SaveImage('babby-current.jpg', cv_data)
            k = boto.s3.key.Key(self.s3bucket)
            if self._snapshot:
                k.key = '/babby/snapshot-%s.jpg' % self._snapshot
                self._snapshot = False
            else:
                k.key = '/babby/current.jpg'
            k.set_contents_from_filename('babby-current.jpg')
            k.set_acl('public-read')
            self._last_img = time.time()