|
@@ -1,13 +1,15 @@
|
|
|
import json
|
|
|
+import cv2
|
|
|
import threading
|
|
|
|
|
|
class MqttObjectPublisher(threading.Thread):
|
|
|
- def __init__(self, client, topic_prefix, objects_parsed, detected_objects):
|
|
|
+ def __init__(self, client, topic_prefix, objects_parsed, detected_objects, best_person_frame):
|
|
|
threading.Thread.__init__(self)
|
|
|
self.client = client
|
|
|
self.topic_prefix = topic_prefix
|
|
|
self.objects_parsed = objects_parsed
|
|
|
self._detected_objects = detected_objects
|
|
|
+ self.best_person_frame = best_person_frame
|
|
|
|
|
|
def run(self):
|
|
|
last_sent_payload = ""
|
|
@@ -30,4 +32,10 @@ class MqttObjectPublisher(threading.Thread):
|
|
|
new_payload = json.dumps(payload, sort_keys=True)
|
|
|
if new_payload != last_sent_payload:
|
|
|
last_sent_payload = new_payload
|
|
|
- self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False)
|
|
|
+ self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False)
|
|
|
+ # send the snapshot over mqtt as well
|
|
|
+ if not self.best_person_frame.best_frame is None:
|
|
|
+ ret, jpg = cv2.imencode('.jpg', self.best_person_frame.best_frame)
|
|
|
+ if ret:
|
|
|
+ jpg_bytes = jpg.tobytes()
|
|
|
+ self.client.publish(self.topic_prefix+'/snapshot', jpg_bytes, retain=True)
|