esp32cam_capture_diff_node: update config format, add ability to resize image with pyssim

This commit is contained in:
Evgeny Zinoviev 2022-06-17 00:06:41 +03:00
parent b3b48406c2
commit fa97ccaa64
2 changed files with 38 additions and 11 deletions

View File

@ -0,0 +1,26 @@
## Dependencies
**pyssim**, which can be installed from pypi:
```
pip3 install pyssim
```
## Configuration
```
esp32cam_web_addr = "192.168.1.2:80"
[pyssim]
bin = "/home/user/.local/bin/pyssim"
width = 250
height = 375
threshold = 0.88
[node]
name = "sensor_node_name"
interval = 15
server_addr = "127.0.0.1:8311"
[logging]
verbose = true
```

View File

@ -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')