opencv video stream on jetson nano code error

I’m trying to transmit a video from Jetsonano’s camera to a server.
However, there was an error when I tried looking at other codes on the web.
Can you take a look at the error code?

server -
address = (’’,1234)

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(address)
server_socket.listen(5)
connection, addr = server_socket.accept()
print(“connected!!”)

data = “”
payload_size = struct.calcsize(“H”)
while True:
while len(data) < payload_size:
data += connection.recv(4096)
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack(“H”, packed_msg_size)[0]
while len(data) < msg_size:
data += connection.recv(4096)
frame_data = data[:msg_size]
data = data[msg_size:]
###

frame = pickle.loads(frame_data)
cv2.imshow('frame', frame)

clent - import socket
import cv2
import numpy
import time
import pickle
import struct

def gstreamer_pipeline(
capture_width=320,
capture_height=240,
display_width=1280,
display_height=720,
framerate=60,
flip_method=0,
):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
“video/x-raw, format=(string)BGR ! appsink”
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)

def show_camera():
# To flip the image, modify the flip_method parameter (0 and 2 are the most common)
#print(gstreamer_pipeline(flip_method=0))
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
address = (’’,1234)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(address)

window_handle = cv2.namedWindow(“CSI Camera”, cv2.WINDOW_AUTOSIZE)

if cap.isOpened():

while True:
    ret, frame = cap.read()
    data = pickle.dumps(frame)
    client_socket.sendall(struct.pack("H",len(data))+data)

    if cv2.waitkey(10) & 0xFF == 27:
        break

#cv2.destoryAllwindows()
cap.release()

client_socket.close()

#else:
#print(“Unable to open camera”)

if name == “main”:
show_camera()

error code -client_socket.sendall(struct.pack(“H”,len(data))+data)
struct.error: ushort format requires 0 <= number <= (0x7fff * 2 + 1)

Traceback (most recent call last):
File “/home/ggg1265/PycharmProjects/prac_cam/receive.py”, line 48, in
data += connection.recv(4096)
TypeError: must be str, not bytes

Hi,
Please check if you can launch the pipeline in the simple code:
https://devtalk.nvidia.com/default/topic/1065637/jetson-agx-xavier/sony-camera-module-cannot-be-opened-with-opencv-on-xavier/post/5397032/#5397032

Replace the string with your usecase:

VideoCapture cap("nvarguscamerasrc ! video/x-raw(memory:NVMM),width=320,height=240,format=NV12,framerate=60/1 ! nvvidconv ! video/x-raw,format=BGRx,width=1280,height=720 ! videoconvert ! video/x-raw,format=BGR ! appsink");