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()
def html(env): option_elems = '' for dev in avail_cameras(): cam = dev.split('/')[-1] option_elems += '<option value="%s">%s</option>' % (cam, cam) html = bytes(HTML_TEMPLATE % option_elems, 'utf-8') header = [('Content-Type', 'text/html'), ('Content-Lentgh', str(len(html)))] return header, html
def record(self, eventid, duration): storage = os.path.join(self.datadir, eventid) if os.path.exists(storage): shutil.rmtree(storage) os.makedirs(storage) self.storage = storage movie_threads = [] devices = self.setting['devices'] if self.setting.get('devices') else avail_cameras() for dev in devices: th = Thread(target=self.rec_video, args=(duration, dev)) th.start() movie_threads.append(th) for th in movie_threads: th.join()
def available(env): available_features = [] if avail_cameras(): available_features.append(('camera', ALL_FEATURES['camera'])) if avail_mikes(): available_features.append(('mike', ALL_FEATURES['mike'])) try: import RPi.GPIO available_features.append(('gpio', ALL_FEATURES['gpio'])) except: pass available_features.append(('gcm', ALL_FEATURES['gcm'])) res = bytes(dumps(available_features), 'utf-8') header = [('Content-Type', 'application/json'), ('Content-Length', str(len(res)))] return header, res
def __init__(self): super().__init__() self.diff_thresh = self.setting.get('diff_threshold', 0.2) if not 0 < self.diff_thresh < 1: raise ValueError('diff_threshold must be between 0 and 1') self.devices = self.setting['devices'] if self.setting.get('devices') else avail_cameras() self.width = int(self.setting.get('width', 320)) self.height = int(self.setting.get('height', 240)) self.max_vector_len = (255**2 * 3)**(1/2) self.target_pixels = [] divnum = self.setting.get('num_of_points', 10) + 1 for i in range(1, divnum): for j in range(1, divnum): self.target_pixels.append((int(i * self.width/divnum), int(j * self.height/divnum))) self.reset()
def devicelist(env): devices = json.dumps([cam.split('/')[-1] for cam in avail_cameras()]) content = bytes(devices, 'utf-8') header = [('Content-Type', 'application/json'), ('Content-Lentgh', str(len(content)))] return header, content