From 883cc84314bacd23ef0e08a36312656396390354 Mon Sep 17 00:00:00 2001 From: Georgios Gerontakis Date: Sat, 11 Jan 2020 19:34:59 +0200 Subject: [PATCH] Adding v1.0.0.0 of streamer/viewer we will later write c# version of viewer for client side for our tracker implementation. --- camera module/streamer.py | 22 ++++++++++++++++++++++ camera module/viewer.py | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 camera module/streamer.py create mode 100755 camera module/viewer.py diff --git a/camera module/streamer.py b/camera module/streamer.py new file mode 100755 index 0000000..382521b --- /dev/null +++ b/camera module/streamer.py @@ -0,0 +1,22 @@ +import base64 +import cv2 +import zmq + +context = zmq.Context() +footage_socket = context.socket(zmq.PUB) +footage_socket.connect('tcp://localhost:5555') + +camera = cv2.VideoCapture(0) # init the camera + +while True: + try: + grabbed, frame = camera.read() # grab the current frame + frame = cv2.resize(frame, (640, 480)) # resize the frame + encoded, buffer = cv2.imencode('.jpg', frame) + jpg_as_text = base64.b64encode(buffer) + footage_socket.send(jpg_as_text) + + except KeyboardInterrupt: + camera.release() + cv2.destroyAllWindows() + break diff --git a/camera module/viewer.py b/camera module/viewer.py new file mode 100755 index 0000000..5db5ca3 --- /dev/null +++ b/camera module/viewer.py @@ -0,0 +1,22 @@ +import cv2 +import zmq +import base64 +import numpy as np + +context = zmq.Context() +footage_socket = context.socket(zmq.SUB) +footage_socket.bind('tcp://*:5555') +footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode('')) + +while True: + try: + frame = footage_socket.recv_string() + img = base64.b64decode(frame) + npimg = np.fromstring(img, dtype=np.uint8) + source = cv2.imdecode(npimg, 1) + cv2.imshow("Stream", source) + cv2.waitKey(1) + + except KeyboardInterrupt: + cv2.destroyAllWindows() + break \ No newline at end of file