I\'m creating a system to share video with opencv but I\'ve got a problem. I\'ve a server and a client but when I send informations to the server, the must be bytes. I send
Your str(frame).encode()
is wrong. If you print it to terminal, then you will find it is not the data of the frame.
An alternative method is to use tobytes()
and frombuffer()
.
## read
ret, frame = cap.read()
sz = frame.shape
## tobytes
frame_bytes = frame.tobytes()
print(type(frame_bytes))
#
## frombuffer and reshape
frame_frombytes = np.frombuffer(frame_bytes, dtype=np.uint8).reshape(sz)
print(type(frame_frombytes))
##
## test whether they equal or not
print(np.array_equal(frame, frame_frombytes))