Exemplo n.º 1
0
def image(env):
    devname = dict(parse_qsl(env.get('QUERY_STRING', ''))).get('device')
    if not devname:
        return [('Content-Type', 'Image/jpeg'), ('Content-Lentgh', '0')], b''

    device_status = CAMERA_STATUS.get(devname, {})
    if device_status.get('in_use', False):
        data = device_status.get('data', b'')

    else:
        device_status['in_use'] =True
        CAMERA_STATUS[devname] = device_status
    
        imgpath = IMGPATH_TMPL % devname
        confpath = CONF_TMPL % devname
        conf = {'device': '/dev/' + devname, 'archive': imgpath, 'text': devname}
        write_webcam_config(conf, confpath)
        capture(confpath)
        with open(imgpath, mode='rb') as f:
            data = f.read()

        device_status['data'] = data
        device_status['in_use'] = False

    header = [('Content-Type', 'Image/jpeg'), ('Content-Length', str(len(data)))]
    return header, data
Exemplo n.º 2
0
    def record(self, eventid, duration):
        storage = os.path.join(self.datadir, eventid)
        if os.path.exists(storage):
            shutil.rmtree(storage)

        self.confs = {}
        camera_threads = []
        devices = self.setting['devices'] if self.setting.get('devices') else avail_cameras()
        for dev in devices:
            devname = dev.split('/')[-1]
            conf = {
                'device': dev,
                'text': '%Y-%m-%d %H:%M:%S ' + devname,
                'archive': os.path.join(storage, devname + '_%H:%M:%S.jpg')
            }
            if self.setting.get('width'):
                conf['width'] = self.setting['width']
            if self.setting.get('height'):
                conf['height'] = self.setting['height']

            conf_file = os.path.join(self.datadir, devname + '.conf')
            write_webcam_config(conf, conf_file)
            self.confs[devname] = conf_file

            camera_threads.append(Thread(target=self.run_camera, args=(devname, duration)))

        for th in camera_threads:
            th.start()
        for th in camera_threads:
            th.join()
Exemplo n.º 3
0
    def update_pixels(self, devname):
        if len(self.pxls[devname]) > 2:
            del(self.pxls[devname][2])
            os.rename(self.filenames[devname]['newest'], self.filenames[devname]['previous'])

        conffile = os.path.join(self.setting.get('tmpdir', '/run/shm'), devname + '.conf')
        conf = {
            'width': self.width,
            'height': self.height,
            'device': '/dev/' + devname,
            'archive': self.filenames[devname]['newest']
        }
        write_webcam_config(conf, conffile)
        capture(conffile)

        img = Image.open(self.filenames[devname]['newest'])
        pxs = [img.getpixel(cood) for cood in self.target_pixels]
        img.close()
        self.pxls[devname].insert(0, pxs)