I want to send an image which was imported by opencv imread to another computer via socket. But the data received and the data sent are not equal.
I have converted the numpy array data which I got by imread and converted it to byte array in order to send it via the socket. And then i have converted the byte array which was received at the other end back to the numpy array. But I can't view the image from the received data.
This is the code snippet in the senders end
im = cv2.imread('view.jpg')
stringimage = np.array_str(im)
byteimage = str.encode(stringimage)
sock.sendto(byteimage,("127.0.0.1",5002))
This is the code snippet in the receivers end
byteimage,addr = sock.recvfrom(1024)
decoded = bytes.decode(byteimage)
backstring = np.array(decoded)
cv2.imshow('RealSense', backstring)
cv2.waitKey(0)
I got this error
TypeError: mat data type = 19 is not supported
for this line of code
cv2.imshow('RealSense', backstring)
Update
After getting the suggestions bellow and referring some other materials I have come up with a solution which is working for my scenario.
Image senders side
#color_image is my opencv image
retval, data = cv2.imencode('.jpg', color_image, ENCODE_PARAMS)
b64_bytes = base64.b64encode(data)
b64_string = b64_bytes.decode()
sock.sendto(str.encode(b64_string), ("127.0.0.1", 5002))
Image receivers side
data, addr = sock.recvfrom(60000)
img = imread(io.BytesIO(base64.b64decode(data)))
Please tell me if there is any bad coding in my solution