def get_current_picture(camera_config, width, height): import mjpgclient jpg = mjpgclient.get_jpg(camera_config['@id']) if jpg is None: return None if width is height is None: return jpg # no server-side resize needed sio = StringIO.StringIO(jpg) image = Image.open(sio) width = width and int(width) or image.size[0] height = height and int(height) or image.size[1] webcam_resolution = camera_config['@webcam_resolution'] max_width = image.size[0] * webcam_resolution / 100 max_height = image.size[1] * webcam_resolution / 100 width = min(max_width, width) height = min(max_height, height) if width >= image.size[0] and height >= image.size[1]: return jpg # no enlarging of the picture on the server side image.thumbnail((width, height), Image.CUBIC) sio = StringIO.StringIO() image.save(sio, format='JPEG') return sio.getvalue()
def get_current_picture(camera_config, width, height): import mjpgclient jpg = mjpgclient.get_jpg(camera_config['@id']) if jpg is None: return None if width is height is None: return jpg # no server-side resize needed #vector fix me: sio = io.StringIO(jpg) #know issues with PIL when changes "REsolution Dimmer" in settings #DEBUG: tag: ExifIFD (34665) - type: long (4) - value: b'\x00\x00\x002' #DEBUG: tag: unknown (34858) - type: signed short (8) - value: b'\x00\x01' sio = io.BytesIO(jpg) image = Image.open(sio) if width and width < 1: # given as percent width = int(width * image.size[0]) if height and height < 1: # given as percent height = int(height * image.size[1]) width = width and int(width) or image.size[0] height = height and int(height) or image.size[1] webcam_resolution = camera_config['@webcam_resolution'] max_width = image.size[0] * webcam_resolution / 100 max_height = image.size[1] * webcam_resolution / 100 width = min(max_width, width) height = min(max_height, height) if width >= image.size[0] and height >= image.size[1]: return jpg # no enlarging of the picture on the server side image.thumbnail((width, height), Image.CUBIC) #vector fix me: sio = io.StringIO() sio = io.BytesIO(jpg) image.save(sio, format='JPEG') return sio.getvalue()
def update(self): while True: if self.stopped: return od_active = False for camera_id in config.get_camera_ids(): #logging.debug('processing camera %s'%camera_id) camera_config = config.get_camera(camera_id) if camera_config['@motion_detection']: if motionctl.is_motion_detected(camera_id): #logging.debug(camera_config) #im_bytes = ODThread.img_todo[camera_id] im_bytes = mjpgclient.get_jpg(camera_id) #ODThread.img_todo[camera_id]=None if im_bytes is not None: # OD has been requested for this camera od_active = True im = self.bytes_to_np(im_bytes) self.process_image(im) if not od_active: time.sleep(ODThread.INACTIVE_SLEEP_TIME)
def start(deferred=False): import mjpgclient if deferred: io_loop = IOLoop.instance() io_loop.add_callback(start, deferred=False) global _started _started = True enabled_local_motion_cameras = config.get_enabled_local_motion_cameras() if running() or not enabled_local_motion_cameras: return logging.debug('starting motion') program = find_motion() if not program: raise Exception('motion executable could not be found') program, version = program # @UnusedVariable logging.debug('using motion binary "%s"' % program) motion_config_path = os.path.join(settings.CONF_PATH, 'motion.conf') motion_log_path = os.path.join(settings.LOG_PATH, 'motion.log') motion_pid_path = os.path.join(settings.RUN_PATH, 'motion.pid') args = [program, '-n', '-c', motion_config_path] args.append('-d') if settings.LOG_LEVEL <= logging.DEBUG: args.append('9') elif settings.LOG_LEVEL <= logging.WARN: args.append('5') elif settings.LOG_LEVEL <= logging.ERROR: args.append('4') else: # fatat, quiet args.append('1') log_file = open(motion_log_path, 'w') process = subprocess.Popen(args, stdout=log_file, stderr=log_file, close_fds=True, cwd=settings.CONF_PATH) # wait 2 seconds to see that the process has successfully started for i in xrange(20): # @UnusedVariable time.sleep(0.1) exit_code = process.poll() if exit_code is not None and exit_code != 0: raise Exception('motion failed to start') pid = process.pid # write the pid to file with open(motion_pid_path, 'w') as f: f.write(str(pid) + '\n') _disable_initial_motion_detection() # if mjpg client idle timeout is disabled, create mjpg clients for all cameras by default if not settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug('creating default mjpg clients for local cameras') for camera in enabled_local_motion_cameras: mjpgclient.get_jpg(camera['@id'])