import cv2 import socket import numpy as np from common import InterlacedPacket, from_bytes_int # bind any IP address UDP_IP = "" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) HEIGHT = 480 WIDTH = 640 frame = np.ndarray((HEIGHT, WIDTH, 3), dtype=np.uint8) while True: # break the array down into 16-bit chunks, then transmit them as UDP packets for i in range(0, HEIGHT, 16): for j in range(0, WIDTH, 16): data, addr = sock.recvfrom(780) # buffer size is 768 bytes # print("received packet from", addr) pkt = from_bytes_int(data) x = pkt.x y = pkt.y arr = pkt.array if pkt.even: frame[y+1:y+32:2, x:x+16] = arr else: frame[y:y + 32:2, x:x + 16] = arr # Display the resulting frame cv2.imshow('Frame', frame) # Break the loop if 'q' key is pressed if cv2.waitKey(1) == ord('q'): break # Release the capture and close all windows cv2.destroyAllWindows()