Cant display python buffer images in unity c# from python (with sockets). I created a rawImage to change its texture, but the texture is not changing

Viewed 46

I was trying to send frames captured with python opencv (server) and display it in unity (client) in real-time via sockets. I created a RawImage in unity and tried to change its texture throw a c# code (client). The code can read the bytes sent but the texture is not changed. Here is my python server code.

import socket, cv2, pickle,struct,imutils


server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_name  = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print('HOST IP:',host_ip)
port = 9999
socket_address = (host_ip,port)


server_socket.bind(socket_address)


server_socket.listen(5)
print("LISTENING AT:",socket_address)

while True:
    client_socket,addr = server_socket.accept()
    print('GOT CONNECTION FROM:',addr)
    if client_socket:
        vid = cv2.VideoCapture(0)
        while(vid.isOpened()):
            img,frame = vid.read()
            frame = imutils.resize(frame,width=320)
            a = pickle.dumps(frame)
            message = struct.pack("Q",len(a))+a
            print(len(a))
            client_socket.sendall(a)
            cv2.imshow('TRANSMITTING VIDEO',frame)
            key = cv2.waitKey(1) & 0xFF
            if key ==ord('q'):
                client_socket.close()

How can I make the c# client in unity that receive this bytes and display it as images by changing the rawimage object texture ?

0 Answers
Related