Extracting keypoints from posenet to a json file?

不羁的心 提交于 2019-12-24 20:31:03

问题


I am looking into the tensorflow implementation of posenet to do pose estimation in real time and also if possible in an offline mode. I am looking into the following repo :

https://github.com/tensorflow/tfjs-models/tree/master/posenet

The keypoints are read out in the following function in the following section of code

    export function drawKeypoints(keypoints, minConfidence, ctx, scale = 1) {
  for (let i = 0; i < keypoints.length; i++) {
    const keypoint = keypoints[i];

    if (keypoint.score < minConfidence) {
      continue;
    }

    const {y, x} = keypoint.position;
    drawPoint(ctx, y * scale, x * scale, 3, color);
  }
}

https://github.com/tensorflow/tfjs-models/blob/master/posenet/demos/demo_util.js

I was looking into the possibility to extract the keypoints to a json file and if it was possible to do so ?

Any tips on this regard would be very helpful .


回答1:


Blob saving to a file is a common way of writing to a file in the browser environment. In the nodejs server, one can use the fs module for that purpose.

Here is a way of doing it in the browser

   var blob = new Blob( [ keypointsData ], {
    type: 'application/octet-stream'
});

var url = URL.createObjectURL( blob );
var link = document.createElement( 'a' );
link.setAttribute( 'href', url );
link.setAttribute( 'download', 'data.json' );
var event = document.createEvent( 'MouseEvents' );
event.initMouseEvent( 'click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent( event );


来源:https://stackoverflow.com/questions/55533698/extracting-keypoints-from-posenet-to-a-json-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!