-1

I have the following code trying to send a prediction result from one machine to another, using PyZMQ.


Viewer :

context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://*:5555')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))

while True:
    frame = footage_socket.recv_string()
    img = base64.b64decode( frame )
    predictions = m1.predict(img)
    print(predictions)

footage_socket.close()

Streamer :

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://localhost:5555')
videoFile = "D:/testing.mp4"
camera = cv2.VideoCapture(videoFile)
count = 0

while True:
    grabbed, frame = camera.read()
    count += 1
    print (count)

    try:
        frame = cv2.resize( frame, (224, 224) )

    except cv2.error:
        break

    image= img_to_array(frame)
    image=image.reshape( ( 1,
                           image.shape[0],
                           image.shape[1],
                           image.shape[2]
                           )
                         )
    image=preprocess_input(image)
    preds=model.predict(image)
    footage_socket.send(preds)
footage_socket.close()

I am receiving this error below :

frame = footage_socket.recv_string()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc6 in position 4:
invalid continuation byte

Thanks help is highly appreciated.

user3666197
  • 1
  • 6
  • 50
  • 92
Mazia
  • 63
  • 1
  • 10

1 Answers1

1

You are sending binary data, but then try to read it as an Unicode string with recv_string().

You need to use footage_socket.recv().

rveerd
  • 3,620
  • 1
  • 14
  • 30
  • Hi, @rveerd, I am really thankful to you for your wonderful help it took me so much time to figure out this but you really saved my time. – Mazia Nov 11 '20 at 09:31