summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/esp32cam_capture_diff_node.md26
-rwxr-xr-xsrc/esp32cam_capture_diff_node.py23
2 files changed, 38 insertions, 11 deletions
diff --git a/doc/esp32cam_capture_diff_node.md b/doc/esp32cam_capture_diff_node.md
new file mode 100644
index 0000000..0fba497
--- /dev/null
+++ b/doc/esp32cam_capture_diff_node.md
@@ -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
+``` \ No newline at end of file
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')