interlace video output
This commit is contained in:
37
client.py
37
client.py
@ -2,7 +2,7 @@ import cv2
|
||||
import socket
|
||||
import numpy as np
|
||||
|
||||
from common import Packet
|
||||
from common import StdPacket, InterlacedPacket
|
||||
|
||||
UDP_IP = "127.0.0.1"
|
||||
UDP_PORT = 5005
|
||||
@ -20,6 +20,31 @@ def send_packet(sock, packet):
|
||||
sock = socket.socket(socket.AF_INET, # Internet
|
||||
socket.SOCK_DGRAM) # UDP
|
||||
|
||||
def breakdown_image_norm(frame):
|
||||
(cols, rows, colors) = frame.shape
|
||||
# break the array down into 16x16 chunks, then transmit them as UDP packets
|
||||
for i in range(0, cols, 16):
|
||||
for j in range(0, rows, 16):
|
||||
# print("Sending frame segment (%d, %d)", i, j)
|
||||
pkt = StdPacket(j, i, frame[i:i + 16, j:j + 16])
|
||||
send_packet(sock, pkt.to_bytestr())
|
||||
|
||||
def breakdown_image_interlaced(frame):
|
||||
(cols, rows, colors) = frame.shape
|
||||
# break the array into 16x32 chunks. we'll split those further into odd and even rows
|
||||
# and send each as UDP packets. this should make packet loss less obvious
|
||||
for i in range(0, cols, 32):
|
||||
for j in range(0, rows, 16):
|
||||
# print("Sending frame segment (%d, %d)", i, j)
|
||||
pkt = InterlacedPacket(j, i, False, frame[i:i + 32:2, j:j + 16])
|
||||
send_packet(sock, pkt.to_bytestr())
|
||||
|
||||
for i in range(0, cols, 32):
|
||||
for j in range(0, rows, 16):
|
||||
# print("Sending frame segment (%d, %d)", i, j)
|
||||
pkt = InterlacedPacket(j, i, True, frame[i + 1:i + 32:2, j:j + 16])
|
||||
send_packet(sock, pkt.to_bytestr())
|
||||
|
||||
while True:
|
||||
# Capture frame-by-frame
|
||||
ret, frame = cap.read()
|
||||
@ -29,15 +54,7 @@ while True:
|
||||
print("Can't receive frame (stream end?). Exiting ...")
|
||||
break
|
||||
|
||||
(cols, rows, colors) = frame.shape
|
||||
|
||||
# break the array down into 16-bit chunks, then transmit them as UDP packets
|
||||
for i in range(0, cols, 16):
|
||||
for j in range(0, rows, 16):
|
||||
print("Sending frame segment (%d, %d)", i, j)
|
||||
pkt = Packet(j, i, frame[i:i+16, j:j+16])
|
||||
send_packet(sock, pkt.to_bytestr())
|
||||
|
||||
breakdown_image_interlaced(frame)
|
||||
|
||||
# Release the capture and close all windows
|
||||
cap.release()
|
Reference in New Issue
Block a user