5

so i'm doing my final project. i want to get head pose estimation from client webcam. i succesfully stream the webcam to server with websocket. but when i try to put my head pose function inside the socket route, the terminal show error valueError: too many packets in payload frequently. does anyone know how to prevent this error ? any answer would be appreciated. thank you !

here's my code for more information.

JavaScript

var constraints = { audio: false, video: { width: 500, height: 500 } }; 
var video = document.querySelector('video');
var canvas = document.querySelector('canvas');

var socket = io('https://0.0.0.0:8000');

navigator.mediaDevices.getUserMedia(constraints)
    .then(function(mediaStream) {
    video.srcObject = mediaStream;
    video.onloadedmetadata = function(e) {
    video.play();

  };
})
.catch(function(err) { console.log(err.name + ": " + err.message); })

socket.on('connect', function () {
    console.log('connected !', socket.connected);

    function capture() {
        canvas.width = 200;
        canvas.height = 200;
        canvas.getContext('2d').drawImage(video, 0, 0, 200, 200);
        var data = canvas.toDataURL('image/jpeg');

        return data;
    };

    var FPS = 50

    setInterval(() => {
        var imgData = capture();

        socket.emit('image', imgData);

    }, 1000 / FPS);
});

flask app

@socketio.on('image')
def image(data_image):
    time.sleep(1)
    encoded_image = data_image.split(",")[1]
    decoded = base64.b64decode(encoded_image)
    frame = cv2.imdecode(np.frombuffer(decoded, np.uint8), -1)

    #this is my head pose module
    pose = FacePosition(frame)

    head_pose = pose.run()
    print(head_pose)

if __name__ == '__main__':
    socketio.run(app, threaded = True)

Farhan Rabbaanii
  • 393
  • 6
  • 16

1 Answers1

5

You may want to take a look at this github issue. Raising enigneio's max_decode_packets did solve that problem for me.

ross933
  • 51
  • 1
  • 1