Browse Source

implement plugin ipc but not complete.

tangs 6 years ago
parent
commit
c251ab62d3
3 changed files with 58 additions and 3 deletions
  1. 9 0
      plugins/base.py
  2. 49 0
      plugins/ipc.py
  3. 0 3
      timing.py

+ 9 - 0
plugins/base.py

@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+class Base:
+    def __init__(self, *args, **kwargs):
+        pass
+
+    def exec(self, *args, **kwargs):
+        pass

+ 49 - 0
plugins/ipc.py

@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+from plugins import base
+from onvif import ONVIFCamera
+from urllib.request import urlretrieve
+from os import path
+import datetime
+
+
+class IPC(base.Base):
+    def __init__(self, *args, **kwargs):
+        base.Base.__init__(*args, **kwargs)
+        self.host = kwargs['host']
+        self.port = kwargs['port']
+        self.user = kwargs['user']
+        self.password = kwargs['password']
+        self.image_dir = kwargs['image_dir']
+        self.wsdl_dir = '../resource/wsdl'
+        if kwargs.__contains__('wsdl_dir') and kwargs['wsdl_dir'] != "":
+            self.wsdl_dir = kwargs['wsdl_dir']
+
+    def exec(self):
+        image_name = self.snapshot()
+
+        analyze_result = self.analyze()
+        return {'data': analyze_result, 'image': image_name}
+
+    def snapshot(self):
+        try:
+            mycam = ONVIFCamera(self.host, self.port, self.user, self.password, self.wsdl_dir)
+            media = mycam.create_media_service()
+            profiles = media.GetProfiles()
+            if len(profiles) < 1:
+                return
+
+            token = profiles[0]['token']
+            snapshot_detail = media.GetSnapshotUri(token)
+            snapshot_url = snapshot_detail['url']
+            image_name = str(int(datetime.datetime.now().timestamp() * 1000)) + ".png"
+
+            # download image via image url
+            urlretrieve(snapshot_url, path.join(self.image_dir, image_name))
+        except Exception as e:
+            return e
+        return image_name
+
+    def analyze(self):
+        return {}

+ 0 - 3
timing.py

@@ -50,9 +50,6 @@ class Timing:
         time.sleep(self.sleep_interval)
 
     def run(self):
-        """
-        :return:
-        """
         while True:
             self.lock.acquire()
             for task_id, task_detail in self.task.keys():