diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-06-17 00:06:41 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-06-17 00:06:41 +0300 |
commit | fa97ccaa64e1819af3296e95dcbe10fa1c6c788d (patch) | |
tree | aa36d837f043b94ed9080cfd1d4c422699f81c75 /src/esp32cam_capture_diff_node.py | |
parent | b3b48406c2e74b65bbe4e2f39771ce3e28110b7b (diff) |
esp32cam_capture_diff_node: update config format, add ability to resize image with pyssim
Diffstat (limited to 'src/esp32cam_capture_diff_node.py')
-rwxr-xr-x | src/esp32cam_capture_diff_node.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/esp32cam_capture_diff_node.py b/src/esp32cam_capture_diff_node.py index 5bbfdf7..38cb5b2 100755 --- a/src/esp32cam_capture_diff_node.py +++ b/src/esp32cam_capture_diff_node.py @@ -15,7 +15,12 @@ cam: Optional[WebClient] = None async def pyssim(fn1: str, fn2: str) -> float: - args = [config['pyssim_path'], fn1, fn2] + args = [config['pyssim']['bin']] + if 'width' in config['pyssim']: + args.extend(['--width', str(config['pyssim']['width'])]) + if 'height' in config['pyssim']: + args.extend(['--height', str(config['pyssim']['height'])]) + args.extend([fn1, fn2]) proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) @@ -48,16 +53,12 @@ class ESP32CamCaptureDiffNode: self.nextpic = 1 if self.nextpic == 2 else 2 if not self.first: - diff = await pyssim(filename, os.path.join(self.directory, self.getfilename())) - logger.debug(f'pyssim: diff={diff}') - n = 0 - if diff < 0.93: - n = 3 - elif n < 0.955: - n = 1 - if n > 0: - logger.info(f'diff = {diff}, informing central server') - send_datagram(stringify([config['node']['name'], n]), self.server_addr) + score = await pyssim(filename, os.path.join(self.directory, self.getfilename())) + logger.debug(f'pyssim: diff={score}') + if score < config['pyssim']['threshold']: + logger.info(f'score = {score}, informing central server') + send_datagram(stringify([config['node']['name'], 2]), self.server_addr) + self.first = False logger.debug('capture: done') |