Georgios Gerontakis
5 years ago
3 changed files with 19 additions and 29 deletions
@ -0,0 +1,12 @@ |
|||||
|
[Unit] |
||||
|
Description=Camera Module Service |
||||
|
After=multi-user.target |
||||
|
Conflicts=getty@tty1.service |
||||
|
|
||||
|
[Service] |
||||
|
Type=simple |
||||
|
ExecStart=/usr/bin/python3 /usr/bin/main.py |
||||
|
StandardInput=tty-force |
||||
|
|
||||
|
[Install] |
||||
|
WantedBy=multi-user.target |
@ -1,29 +0,0 @@ |
|||||
import base64 |
|
||||
import cv2 |
|
||||
import zmq |
|
||||
|
|
||||
context = zmq.Context() |
|
||||
|
|
||||
socket = context.socket(zmq.REP) |
|
||||
socket.bind("tcp://*:4444") |
|
||||
while True: |
|
||||
client_ip = socket.recv() |
|
||||
break |
|
||||
|
|
||||
footage_socket = context.socket(zmq.PUB) |
|
||||
footage_socket.connect('tcp://' + client_ip.decode() + ':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 |
|
Loading…
Reference in new issue