---
# System prepended metadata

title: Neo Bio Recon

---

# Neo Bio Recon

# Enlaces

* Github Project
server code:
```python=
import socket
import sys
import time

import numpy as np
import struct ## new
import zlib
from _thread import *
import cv2
import pickle
import numpy as np
import struct ## new
import zlib




def ReciveData(conn):
	data = b""
	payload_size = struct.calcsize(">L")
	print(payload_size)
	print("payload_size: {}".format(payload_size))

	while True:
		while len(data) < payload_size:
			newdata = conn.recv(4096)
			if newdata == b"":
				
				return 0
			#print("Recv: {}".format(len(data)))
			data += newdata
	
		print("Done Recv: {}".format(len(data)))
		packed_msg_size = data[:payload_size]
		data = data[payload_size:]
		msg_size = struct.unpack(">L", packed_msg_size)[0]
		print("msg_size: {}".format(msg_size))
		while len(data) < msg_size:
			data += conn.recv(4096)
		frame_data = data[:msg_size]
		data = data[msg_size:]
	
		frame=pickle.loads(frame_data, fix_imports=True, encoding="bytes")
		frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
		yield frame


def Server():

	HOST='192.168.17.2'
	PORT=8485

	# Socket listening on specified port
	s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
	print('Socket created')
	try:
		s.bind((HOST,PORT))
		print('Socket bind complete')
		s.listen(10)
		print('Socket now listening')
	except socket.error as e:
		print("SOCKET ERROR")
		print(str(e))
		s.close()
		exit(0)

	return s

def ConnectionHandler(s):
	while True:
		conn,addr=s.accept()
		print("connection from ", addr[0])
		yield conn

def ShowImage(conn):
	name = str(time.time())
	cv2.namedWindow(name, cv2.WINDOW_NORMAL)
	for frame in ReciveData(conn):
		cv2.imshow(name, frame)
		cv2.waitKey(1)
	cv2.destroyWindow(name)



	
def Main():
	s = Server()
	for conn in ConnectionHandler(s):
		start_new_thread(ShowImage,(conn,))




	# Receive new connections on the port

		
		
		ReciveData(conn)


if __name__ == '__main__':
	Main()



def MonitorServer():
	ServerSocket = socket.socket()
	host = '0.0.0.0'
	port = 50051
	try:
		ServerSocket.bind((host, port))
		print(Logdate(),'Server Monitor Started..')
		ServerSocket.listen(5)
		UpdateACL()
	except socket.error as e:
		print(str(e))
		exit(0)

	while True:
		Client, address = ServerSocket.accept()        # IP   Port
		start_new_thread(ThreadedMonitor, (Client,address[0],address[1]))
	ServerSocket.close()



```
client code: 
```python=0
import cv2
import io
import socket
import struct
import time
import pickle
import zlib

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('192.168.17.2', 8485))
connection = client_socket.makefile('wb')

cam = cv2.VideoCapture(0)

cam.set(15, 19980);
cam.set(12, 14500);

img_counter = 0

encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]

while True:
    ret, frame = cam.read()
    result, frame = cv2.imencode('.jpg', frame, encode_param)
	
    data = pickle.dumps(frame, 0)
    size = len(data)


    print("{}: {}".format(img_counter, size))
    client_socket.sendall(struct.pack(">L", size) + data)
    img_counter += 1


client_socket.close()
cam.release()
```

* Face
    * https://www.youtube.com/watch?v=cZkpaL36fW4 
    * https://thecleverprogrammer.com/2020/06/25/image-processing-with-machine-learning-and-python/
    * https://pythondiario.com/2018/07/proyecto-r-face-reconocimiento-facial.html

* Voice
    * https://github.com/rhythmize/user-authentication-using-voice-biometrics