Socket
Socket
Sign inDemoInstall

@tensorflow-models/handpose

Package Overview
Dependencies
31
Maintainers
8
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

dist/box.d.ts

14

dist/hand.js

@@ -57,3 +57,3 @@ "use strict";

var HandDetector = /** @class */ (function () {
function HandDetector(model, width, height, anchors, iouThreshold, scoreThreshold) {
function HandDetector(model, width, height, anchorsAnnotated, iouThreshold, scoreThreshold) {
this.model = model;

@@ -64,3 +64,3 @@ this.width = width;

this.scoreThreshold = scoreThreshold;
this.anchors = anchors.map(function (anchor) { return [anchor.x_center, anchor.y_center]; });
this.anchors = anchorsAnnotated.map(function (anchor) { return [anchor.x_center, anchor.y_center]; });
this.anchorsTensor = tf.tensor2d(this.anchors);

@@ -85,3 +85,3 @@ this.inputSizeTensor = tf.tensor1d([width, height]);

return tf.tidy(function () {
var landmarks = tf.add(tf.div(rawPalmLandmarks.reshape([-1, 7, 2]), _this.inputSizeTensor), _this.anchors[index]);
var landmarks = tf.add(tf.div(tf.reshape(rawPalmLandmarks, [-1, 7, 2]), _this.inputSizeTensor), _this.anchors[index]);
return tf.mul(landmarks, _this.inputSizeTensor);

@@ -109,4 +109,4 @@ });

}
prediction = batchedPrediction.squeeze();
scores = tf.tidy(function () { return tf.sigmoid(tf.slice(prediction, [0, 0], [-1, 1])).squeeze(); });
prediction = tf.squeeze(batchedPrediction);
scores = tf.tidy(function () { return tf.squeeze(tf.sigmoid(tf.slice(prediction, [0, 0], [-1, 1]))); });
rawBoxes = tf.slice(prediction, [0, 1], [-1, 4]);

@@ -132,3 +132,3 @@ boxes = this.normalizeBoxes(rawBoxes);

rawPalmLandmarks = tf.slice(prediction, [boxIndex, 5], [1, 14]);
palmLandmarks = tf.tidy(function () { return _this.normalizeLandmarks(rawPalmLandmarks, boxIndex).reshape([
palmLandmarks = tf.tidy(function () { return tf.reshape(_this.normalizeLandmarks(rawPalmLandmarks, boxIndex), [
-1, 2

@@ -158,3 +158,3 @@ ]); });

inputWidth = input.shape[2];
image = tf.tidy(function () { return input.resizeBilinear([_this.width, _this.height]).div(255); });
image = tf.tidy(function () { return tf.div(tf.image.resizeBilinear(input, [_this.width, _this.height]), 255); });
return [4 /*yield*/, this.getBoundingBoxes(image)];

@@ -161,0 +161,0 @@ case 1:

/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -17,2 +17,2 @@ * you may not use this file except in compliance with the License.

*/
import{loadGraphModel as t}from"@tensorflow/tfjs-converter";import{image as n,tensor2d as e,tensor1d as r,tidy as o,slice as i,add as s,div as a,mul as u,sub as h,concat2d as d,getBackend as c,env as f,sigmoid as l,reshape as p,util as m,Tensor as v,browser as P}from"@tensorflow/tfjs-core";function g(t,n,e,r){return new(e||(e=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,a)}u((r=r.apply(t,n||[])).next())}))}function b(t,n){var e,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;s;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(t,s)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function k(t){return[Math.abs(t.endPoint[0]-t.startPoint[0]),Math.abs(t.endPoint[1]-t.startPoint[1])]}function x(t){return[t.startPoint[0]+(t.endPoint[0]-t.startPoint[0])/2,t.startPoint[1]+(t.endPoint[1]-t.startPoint[1])/2]}function y(t,n){void 0===n&&(n=1.5);var e=x(t),r=k(t),o=[n*r[0]/2,n*r[1]/2];return{startPoint:[e[0]-o[0],e[1]-o[1]],endPoint:[e[0]+o[0],e[1]+o[1]],palmLandmarks:t.palmLandmarks}}function w(t){var n=x(t),e=k(t),r=Math.max.apply(Math,e)/2;return{startPoint:[n[0]-r,n[1]-r],endPoint:[n[0]+r,n[1]+r],palmLandmarks:t.palmLandmarks}}function L(t,n){var e=[t.endPoint[0]-t.startPoint[0],t.endPoint[1]-t.startPoint[1]],r=[e[0]*n[0],e[1]*n[1]];return{startPoint:[t.startPoint[0]+r[0],t.startPoint[1]+r[1]],endPoint:[t.endPoint[0]+r[0],t.endPoint[1]+r[1]],palmLandmarks:t.palmLandmarks}}var B=function(){function t(t,n,o,i,s,a){this.model=t,this.width=n,this.height=o,this.iouThreshold=s,this.scoreThreshold=a,this.anchors=i.map((function(t){return[t.x_center,t.y_center]})),this.anchorsTensor=e(this.anchors),this.inputSizeTensor=r([n,o]),this.doubleInputSizeTensor=r([2*n,2*o])}return t.prototype.normalizeBoxes=function(t){var n=this;return o((function(){var e=i(t,[0,0],[-1,2]),r=i(t,[0,2],[-1,2]),o=s(a(e,n.inputSizeTensor),n.anchorsTensor),c=a(r,n.doubleInputSizeTensor),f=u(h(o,c),n.inputSizeTensor),l=u(s(o,c),n.inputSizeTensor);return d([f,l],1)}))},t.prototype.normalizeLandmarks=function(t,n){var e=this;return o((function(){var r=s(a(t.reshape([-1,7,2]),e.inputSizeTensor),e.anchors[n]);return u(r,e.inputSizeTensor)}))},t.prototype.getBoundingBoxes=function(t){return g(this,void 0,void 0,(function(){var e,r,s,a,d,p,m,v,P,g,k,x,y,w,L,B=this;return b(this,(function(b){switch(b.label){case 0:return e=o((function(){return u(h(t,.5),2)})),"webgl"===c()?(s=f().get("WEBGL_PACK_DEPTHWISECONV"),f().set("WEBGL_PACK_DEPTHWISECONV",!0),r=this.model.predict(e),f().set("WEBGL_PACK_DEPTHWISECONV",s)):r=this.model.predict(e),a=r.squeeze(),d=o((function(){return l(i(a,[0,0],[-1,1])).squeeze()})),p=i(a,[0,1],[-1,4]),m=this.normalizeBoxes(p),v=console.warn,console.warn=function(){},P=n.nonMaxSuppression(m,d,1,this.iouThreshold,this.scoreThreshold),console.warn=v,[4,P.array()];case 1:return g=b.sent(),k=[e,r,P,a,m,p,d],0===g.length?(k.forEach((function(t){return t.dispose()})),[2,null]):(x=g[0],y=i(m,[x,0],[1,-1]),w=i(a,[x,5],[1,14]),L=o((function(){return B.normalizeLandmarks(w,x).reshape([-1,2])})),k.push(w),k.forEach((function(t){return t.dispose()})),[2,{boxes:y,palmLandmarks:L}])}}))}))},t.prototype.estimateHandBounds=function(t){return g(this,void 0,void 0,(function(){var n,e,r,i,s,a,u,h,d=this;return b(this,(function(c){switch(c.label){case 0:return n=t.shape[1],e=t.shape[2],r=o((function(){return t.resizeBilinear([d.width,d.height]).div(255)})),[4,this.getBoundingBoxes(r)];case 1:return null===(i=c.sent())?(r.dispose(),[2,null]):(s=i.boxes.arraySync(),a=s[0].slice(0,2),u=s[0].slice(2,4),h=i.palmLandmarks.arraySync(),r.dispose(),i.boxes.dispose(),i.palmLandmarks.dispose(),[2,(f={startPoint:a,endPoint:u,palmLandmarks:h},l=[e/this.width,n/this.height],{startPoint:[f.startPoint[0]*l[0],f.startPoint[1]*l[1]],endPoint:[f.endPoint[0]*l[0],f.endPoint[1]*l[1]],palmLandmarks:f.palmLandmarks.map((function(t){return[t[0]*l[0],t[1]*l[1]]}))})])}var f,l}))}))},t}(),I={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]};function C(t,n){var e,r=Math.PI/2-Math.atan2(-(n[1]-t[1]),n[0]-t[0]);return(e=r)-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}var H=function(t,n){return[[1,0,t],[0,1,n],[0,0,1]]};function M(t,n){for(var e=0,r=0;r<t.length;r++)e+=t[r]*n[r];return e}function T(t,n){for(var e=[],r=0;r<t.length;r++)e.push(t[r][n]);return e}function E(t,n){for(var e=[],r=t.length,o=0;o<r;o++){e.push([]);for(var i=0;i<r;i++)e[o].push(M(t[o],T(n,i)))}return e}function O(t,n){var e=Math.cos(t),r=Math.sin(t),o=[[e,-r,0],[r,e,0],[0,0,1]],i=E(H(n[0],n[1]),o);return E(i,H(-n[0],-n[1]))}function S(t,n){return[M(t,n[0]),M(t,n[1])]}var W=[0,-.4],z=[0,-.1],D=[0,5,9,13,17,1,2],_=function(){function t(t,n,e,r,o,i){this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.boundingBoxDetector=t,this.meshDetector=n,this.maxContinuousChecks=o,this.detectionConfidence=i,this.meshWidth=e,this.meshHeight=r,this.maxHandsNumber=1}return t.prototype.getBoxForPalmLandmarks=function(t,n){var e=t.map((function(t){return S(t.concat([1]),n)}));return y(w(L(this.calculateLandmarksBoundingBox(e),W)),3)},t.prototype.getBoxForHandLandmarks=function(t){for(var n=y(w(L(this.calculateLandmarksBoundingBox(t),z)),1.65),e=[],r=0;r<D.length;r++)e.push(t[D[r]].slice(0,2));return n.palmLandmarks=e,n},t.prototype.transformRawCoords=function(t,n,e,r){var o,i,s,a,u=this,h=k(n),d=[h[0]/this.meshWidth,h[1]/this.meshHeight],c=t.map((function(t){return[d[0]*(t[0]-u.meshWidth/2),d[1]*(t[1]-u.meshHeight/2),t[2]]})),f=O(e,[0,0]),l=c.map((function(t){return S(t,f).concat([t[2]])})),p=(i=[[(o=r)[0][0],o[1][0]],[o[0][1],o[1][1]]],s=[o[0][2],o[1][2]],a=[-M(i[0],s),-M(i[1],s)],[i[0].concat(a[0]),i[1].concat(a[1]),[0,0,1]]),m=x(n).concat([1]),v=[M(m,p[0]),M(m,p[1])];return l.map((function(t){return[t[0]+v[0],t[1]+v[1],t[2]]}))},t.prototype.estimateHand=function(t){return g(this,void 0,void 0,(function(){var e,r,o,i,s,a,u,h,d,l,m,v,P,g,k,y,w,L,B,I;return b(this,(function(b){switch(b.label){case 0:return!0!==(e=this.shouldUpdateRegionsOfInterest())?[3,2]:[4,this.boundingBoxDetector.estimateHandBounds(t)];case 1:return null===(r=b.sent())?(t.dispose(),this.regionsOfInterest=[],[2,null]):(this.updateRegionsOfInterest(r,!0),this.runsWithoutHandDetector=0,[3,3]);case 2:this.runsWithoutHandDetector++,b.label=3;case 3:return o=this.regionsOfInterest[0],i=C(o.palmLandmarks[0],o.palmLandmarks[2]),s=x(o),a=[s[0]/t.shape[2],s[1]/t.shape[1]],u=n.rotateWithOffset(t,i,0,a),h=O(-i,s),d=!0===e?this.getBoxForPalmLandmarks(o.palmLandmarks,h):o,l=function(t,e,r){var o=e.shape[1],i=e.shape[2],s=[[t.startPoint[1]/o,t.startPoint[0]/i,t.endPoint[1]/o,t.endPoint[0]/i]];return n.cropAndResize(e,s,[0],r)}(d,u,[this.meshWidth,this.meshHeight]),m=l.div(255),l.dispose(),u.dispose(),"webgl"===c()?(P=f().get("WEBGL_PACK_DEPTHWISECONV"),f().set("WEBGL_PACK_DEPTHWISECONV",!0),v=this.meshDetector.predict(m),f().set("WEBGL_PACK_DEPTHWISECONV",P)):v=this.meshDetector.predict(m),g=v[0],k=v[1],m.dispose(),y=g.dataSync()[0],g.dispose(),y<this.detectionConfidence?(k.dispose(),this.regionsOfInterest=[],[2,null]):(w=p(k,[-1,3]),L=w.arraySync(),k.dispose(),w.dispose(),B=this.transformRawCoords(L,d,i,h),I=this.getBoxForHandLandmarks(B),this.updateRegionsOfInterest(I,!1),[2,{landmarks:B,handInViewConfidence:y,boundingBox:{topLeft:I.startPoint,bottomRight:I.endPoint}}])}}))}))},t.prototype.calculateLandmarksBoundingBox=function(t){var n=t.map((function(t){return t[0]})),e=t.map((function(t){return t[1]}));return{startPoint:[Math.min.apply(Math,n),Math.min.apply(Math,e)],endPoint:[Math.max.apply(Math,n),Math.max.apply(Math,e)]}},t.prototype.updateRegionsOfInterest=function(t,n){if(n)this.regionsOfInterest=[t];else{var e=this.regionsOfInterest[0],r=0;if(null!=e&&null!=e.startPoint){var o=t.startPoint,i=o[0],s=o[1],a=t.endPoint,u=a[0],h=a[1],d=e.startPoint,c=d[0],f=d[1],l=e.endPoint,p=l[0],m=l[1],v=Math.max(i,c),P=Math.max(s,f),g=(Math.min(u,p)-v)*(Math.min(h,m)-P);r=g/((u-i)*(h-s)+(p-c)*(m-s)-g)}this.regionsOfInterest[0]=r>.8?e:t}},t.prototype.shouldUpdateRegionsOfInterest=function(){return this.regionsOfInterest.length!==this.maxHandsNumber||this.runsWithoutHandDetector>=this.maxContinuousChecks},t}();function R(){return g(this,void 0,void 0,(function(){return b(this,(function(n){return"https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",[2,t("https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",{fromTFHub:!0})]}))}))}function j(){return g(this,void 0,void 0,(function(){return b(this,(function(n){return"https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",[2,t("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",{fromTFHub:!0})]}))}))}function V(){return g(this,void 0,void 0,(function(){return b(this,(function(t){return[2,m.fetch("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1/anchors.json?tfjs-format=file").then((function(t){return t.json()}))]}))}))}function F(t){var n=void 0===t?{}:t,e=n.maxContinuousChecks,r=void 0===e?1/0:e,o=n.detectionConfidence,i=void 0===o?.8:o,s=n.iouThreshold,a=void 0===s?.3:s,u=n.scoreThreshold,h=void 0===u?.5:u;return g(this,void 0,void 0,(function(){var t,n,e,o,s,u;return b(this,(function(d){switch(d.label){case 0:return[4,Promise.all([V(),R(),j()])];case 1:return t=d.sent(),n=t[0],e=t[1],o=t[2],s=new B(e,256,256,n,a,h),u=new _(s,o,256,256,r,i),[2,new A(u)]}}))}))}var A=function(){function t(t){this.pipeline=t}return t.getAnnotations=function(){return I},t.prototype.estimateHands=function(t,n){return void 0===n&&(n=!1),g(this,void 0,void 0,(function(){var e,r,i,s,a,u,h,d,c;return b(this,(function(f){switch(f.label){case 0:return e=function(t){return t instanceof v?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),r=e[1],i=o((function(){return t instanceof v||(t=P.fromPixels(t)),t.toFloat().expandDims(0)})),[4,this.pipeline.estimateHand(i)];case 1:if(s=f.sent(),i.dispose(),null===s)return[2,[]];for(a=s,!0===n&&(a=function(t,n){var e=t.handInViewConfidence,r=t.landmarks,o=t.boundingBox;return{handInViewConfidence:e,landmarks:r.map((function(t){return[n-1-t[0],t[1],t[2]]})),boundingBox:{topLeft:[n-1-o.topLeft[0],o.topLeft[1]],bottomRight:[n-1-o.bottomRight[0],o.bottomRight[1]]}}}(s,r)),u={},h=0,d=Object.keys(I);h<d.length;h++)c=d[h],u[c]=I[c].map((function(t){return a.landmarks[t]}));return[2,[{handInViewConfidence:a.handInViewConfidence,boundingBox:a.boundingBox,landmarks:a.landmarks,annotations:u}]]}}))}))},t}();export{A as HandPose,F as load};
import{loadGraphModel as t}from"@tensorflow/tfjs-converter";import{image as n,tensor2d as e,tensor1d as r,tidy as o,slice as i,add as s,div as a,mul as u,sub as h,concat2d as d,reshape as c,getBackend as f,env as l,squeeze as p,sigmoid as m,util as v,Tensor as P,browser as g,expandDims as b,cast as k}from"@tensorflow/tfjs-core";function y(t,n,e,r){return new(e||(e=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function a(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,a)}u((r=r.apply(t,n||[])).next())}))}function x(t,n){var e,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;s;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(t,s)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function w(t){return[Math.abs(t.endPoint[0]-t.startPoint[0]),Math.abs(t.endPoint[1]-t.startPoint[1])]}function L(t){return[t.startPoint[0]+(t.endPoint[0]-t.startPoint[0])/2,t.startPoint[1]+(t.endPoint[1]-t.startPoint[1])/2]}function B(t,n){void 0===n&&(n=1.5);var e=L(t),r=w(t),o=[n*r[0]/2,n*r[1]/2];return{startPoint:[e[0]-o[0],e[1]-o[1]],endPoint:[e[0]+o[0],e[1]+o[1]],palmLandmarks:t.palmLandmarks}}function I(t){var n=L(t),e=w(t),r=Math.max.apply(Math,e)/2;return{startPoint:[n[0]-r,n[1]-r],endPoint:[n[0]+r,n[1]+r],palmLandmarks:t.palmLandmarks}}function C(t,n){var e=[t.endPoint[0]-t.startPoint[0],t.endPoint[1]-t.startPoint[1]],r=[e[0]*n[0],e[1]*n[1]];return{startPoint:[t.startPoint[0]+r[0],t.startPoint[1]+r[1]],endPoint:[t.endPoint[0]+r[0],t.endPoint[1]+r[1]],palmLandmarks:t.palmLandmarks}}var H=function(){function t(t,n,o,i,s,a){this.model=t,this.width=n,this.height=o,this.iouThreshold=s,this.scoreThreshold=a,this.anchors=i.map((function(t){return[t.x_center,t.y_center]})),this.anchorsTensor=e(this.anchors),this.inputSizeTensor=r([n,o]),this.doubleInputSizeTensor=r([2*n,2*o])}return t.prototype.normalizeBoxes=function(t){var n=this;return o((function(){var e=i(t,[0,0],[-1,2]),r=i(t,[0,2],[-1,2]),o=s(a(e,n.inputSizeTensor),n.anchorsTensor),c=a(r,n.doubleInputSizeTensor),f=u(h(o,c),n.inputSizeTensor),l=u(s(o,c),n.inputSizeTensor);return d([f,l],1)}))},t.prototype.normalizeLandmarks=function(t,n){var e=this;return o((function(){var r=s(a(c(t,[-1,7,2]),e.inputSizeTensor),e.anchors[n]);return u(r,e.inputSizeTensor)}))},t.prototype.getBoundingBoxes=function(t){return y(this,void 0,void 0,(function(){var e,r,s,a,d,v,P,g,b,k,y,w,L,B,I,C=this;return x(this,(function(x){switch(x.label){case 0:return e=o((function(){return u(h(t,.5),2)})),"webgl"===f()?(s=l().get("WEBGL_PACK_DEPTHWISECONV"),l().set("WEBGL_PACK_DEPTHWISECONV",!0),r=this.model.predict(e),l().set("WEBGL_PACK_DEPTHWISECONV",s)):r=this.model.predict(e),a=p(r),d=o((function(){return p(m(i(a,[0,0],[-1,1])))})),v=i(a,[0,1],[-1,4]),P=this.normalizeBoxes(v),g=console.warn,console.warn=function(){},b=n.nonMaxSuppression(P,d,1,this.iouThreshold,this.scoreThreshold),console.warn=g,[4,b.array()];case 1:return k=x.sent(),y=[e,r,b,a,P,v,d],0===k.length?(y.forEach((function(t){return t.dispose()})),[2,null]):(w=k[0],L=i(P,[w,0],[1,-1]),B=i(a,[w,5],[1,14]),I=o((function(){return c(C.normalizeLandmarks(B,w),[-1,2])})),y.push(B),y.forEach((function(t){return t.dispose()})),[2,{boxes:L,palmLandmarks:I}])}}))}))},t.prototype.estimateHandBounds=function(t){return y(this,void 0,void 0,(function(){var e,r,i,s,u,h,d,c,f=this;return x(this,(function(l){switch(l.label){case 0:return e=t.shape[1],r=t.shape[2],i=o((function(){return a(n.resizeBilinear(t,[f.width,f.height]),255)})),[4,this.getBoundingBoxes(i)];case 1:return null===(s=l.sent())?(i.dispose(),[2,null]):(u=s.boxes.arraySync(),h=u[0].slice(0,2),d=u[0].slice(2,4),c=s.palmLandmarks.arraySync(),i.dispose(),s.boxes.dispose(),s.palmLandmarks.dispose(),[2,(p={startPoint:h,endPoint:d,palmLandmarks:c},m=[r/this.width,e/this.height],{startPoint:[p.startPoint[0]*m[0],p.startPoint[1]*m[1]],endPoint:[p.endPoint[0]*m[0],p.endPoint[1]*m[1]],palmLandmarks:p.palmLandmarks.map((function(t){return[t[0]*m[0],t[1]*m[1]]}))})])}var p,m}))}))},t}(),M={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]};function T(t,n){var e,r=Math.PI/2-Math.atan2(-(n[1]-t[1]),n[0]-t[0]);return(e=r)-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}var E=function(t,n){return[[1,0,t],[0,1,n],[0,0,1]]};function O(t,n){for(var e=0,r=0;r<t.length;r++)e+=t[r]*n[r];return e}function S(t,n){for(var e=[],r=0;r<t.length;r++)e.push(t[r][n]);return e}function W(t,n){for(var e=[],r=t.length,o=0;o<r;o++){e.push([]);for(var i=0;i<r;i++)e[o].push(O(t[o],S(n,i)))}return e}function D(t,n){var e=Math.cos(t),r=Math.sin(t),o=[[e,-r,0],[r,e,0],[0,0,1]],i=W(E(n[0],n[1]),o);return W(i,E(-n[0],-n[1]))}function z(t,n){return[O(t,n[0]),O(t,n[1])]}var _=[0,-.4],R=[0,-.1],j=[0,5,9,13,17,1,2],V=function(){function t(t,n,e,r,o,i){this.boundingBoxDetector=t,this.meshDetector=n,this.meshWidth=e,this.meshHeight=r,this.maxContinuousChecks=o,this.detectionConfidence=i,this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.maxHandsNumber=1}return t.prototype.getBoxForPalmLandmarks=function(t,n){var e=t.map((function(t){return z(t.concat([1]),n)}));return B(I(C(this.calculateLandmarksBoundingBox(e),_)),3)},t.prototype.getBoxForHandLandmarks=function(t){for(var n=B(I(C(this.calculateLandmarksBoundingBox(t),R)),1.65),e=[],r=0;r<j.length;r++)e.push(t[j[r]].slice(0,2));return n.palmLandmarks=e,n},t.prototype.transformRawCoords=function(t,n,e,r){var o,i,s,a,u=this,h=w(n),d=[h[0]/this.meshWidth,h[1]/this.meshHeight],c=t.map((function(t){return[d[0]*(t[0]-u.meshWidth/2),d[1]*(t[1]-u.meshHeight/2),t[2]]})),f=D(e,[0,0]),l=c.map((function(t){return z(t,f).concat([t[2]])})),p=(i=[[(o=r)[0][0],o[1][0]],[o[0][1],o[1][1]]],s=[o[0][2],o[1][2]],a=[-O(i[0],s),-O(i[1],s)],[i[0].concat(a[0]),i[1].concat(a[1]),[0,0,1]]),m=L(n).concat([1]),v=[O(m,p[0]),O(m,p[1])];return l.map((function(t){return[t[0]+v[0],t[1]+v[1],t[2]]}))},t.prototype.estimateHand=function(t){return y(this,void 0,void 0,(function(){var e,r,o,i,s,u,h,d,p,m,v,P,g,b,k,y,w,B,I,C;return x(this,(function(x){switch(x.label){case 0:return!0!==(e=this.shouldUpdateRegionsOfInterest())?[3,2]:[4,this.boundingBoxDetector.estimateHandBounds(t)];case 1:return null===(r=x.sent())?(t.dispose(),this.regionsOfInterest=[],[2,null]):(this.updateRegionsOfInterest(r,!0),this.runsWithoutHandDetector=0,[3,3]);case 2:this.runsWithoutHandDetector++,x.label=3;case 3:return o=this.regionsOfInterest[0],i=T(o.palmLandmarks[0],o.palmLandmarks[2]),s=L(o),u=[s[0]/t.shape[2],s[1]/t.shape[1]],h=n.rotateWithOffset(t,i,0,u),d=D(-i,s),p=!0===e?this.getBoxForPalmLandmarks(o.palmLandmarks,d):o,m=function(t,e,r){var o=e.shape[1],i=e.shape[2],s=[[t.startPoint[1]/o,t.startPoint[0]/i,t.endPoint[1]/o,t.endPoint[0]/i]];return n.cropAndResize(e,s,[0],r)}(p,h,[this.meshWidth,this.meshHeight]),v=a(m,255),m.dispose(),h.dispose(),"webgl"===f()?(g=l().get("WEBGL_PACK_DEPTHWISECONV"),l().set("WEBGL_PACK_DEPTHWISECONV",!0),P=this.meshDetector.predict(v),l().set("WEBGL_PACK_DEPTHWISECONV",g)):P=this.meshDetector.predict(v),b=P[0],k=P[1],v.dispose(),y=b.dataSync()[0],b.dispose(),y<this.detectionConfidence?(k.dispose(),this.regionsOfInterest=[],[2,null]):(w=c(k,[-1,3]),B=w.arraySync(),k.dispose(),w.dispose(),I=this.transformRawCoords(B,p,i,d),C=this.getBoxForHandLandmarks(I),this.updateRegionsOfInterest(C,!1),[2,{landmarks:I,handInViewConfidence:y,boundingBox:{topLeft:C.startPoint,bottomRight:C.endPoint}}])}}))}))},t.prototype.calculateLandmarksBoundingBox=function(t){var n=t.map((function(t){return t[0]})),e=t.map((function(t){return t[1]}));return{startPoint:[Math.min.apply(Math,n),Math.min.apply(Math,e)],endPoint:[Math.max.apply(Math,n),Math.max.apply(Math,e)]}},t.prototype.updateRegionsOfInterest=function(t,n){if(n)this.regionsOfInterest=[t];else{var e=this.regionsOfInterest[0],r=0;if(null!=e&&null!=e.startPoint){var o=t.startPoint,i=o[0],s=o[1],a=t.endPoint,u=a[0],h=a[1],d=e.startPoint,c=d[0],f=d[1],l=e.endPoint,p=l[0],m=l[1],v=Math.max(i,c),P=Math.max(s,f),g=(Math.min(u,p)-v)*(Math.min(h,m)-P);r=g/((u-i)*(h-s)+(p-c)*(m-s)-g)}this.regionsOfInterest[0]=r>.8?e:t}},t.prototype.shouldUpdateRegionsOfInterest=function(){return this.regionsOfInterest.length!==this.maxHandsNumber||this.runsWithoutHandDetector>=this.maxContinuousChecks},t}();function F(){return y(this,void 0,void 0,(function(){return x(this,(function(n){return"https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",[2,t("https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",{fromTFHub:!0})]}))}))}function A(){return y(this,void 0,void 0,(function(){return x(this,(function(n){return"https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",[2,t("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",{fromTFHub:!0})]}))}))}function N(){return y(this,void 0,void 0,(function(){return x(this,(function(t){return[2,v.fetch("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1/anchors.json?tfjs-format=file").then((function(t){return t.json()}))]}))}))}function G(t){var n=void 0===t?{}:t,e=n.maxContinuousChecks,r=void 0===e?1/0:e,o=n.detectionConfidence,i=void 0===o?.8:o,s=n.iouThreshold,a=void 0===s?.3:s,u=n.scoreThreshold,h=void 0===u?.5:u;return y(this,void 0,void 0,(function(){var t,n,e,o,s,u;return x(this,(function(d){switch(d.label){case 0:return[4,Promise.all([N(),F(),A()])];case 1:return t=d.sent(),n=t[0],e=t[1],o=t[2],s=new H(e,256,256,n,a,h),u=new V(s,o,256,256,r,i),[2,new K(u)]}}))}))}var K=function(){function t(t){this.pipeline=t}return t.getAnnotations=function(){return M},t.prototype.estimateHands=function(t,n){return void 0===n&&(n=!1),y(this,void 0,void 0,(function(){var e,r,i,s,a,u,h,d,c;return x(this,(function(f){switch(f.label){case 0:return e=function(t){return t instanceof P?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),r=e[1],i=o((function(){return t instanceof P||(t=g.fromPixels(t)),b(k(t,"float32"))})),[4,this.pipeline.estimateHand(i)];case 1:if(s=f.sent(),i.dispose(),null===s)return[2,[]];for(a=s,!0===n&&(a=function(t,n){var e=t.handInViewConfidence,r=t.landmarks,o=t.boundingBox;return{handInViewConfidence:e,landmarks:r.map((function(t){return[n-1-t[0],t[1],t[2]]})),boundingBox:{topLeft:[n-1-o.topLeft[0],o.topLeft[1]],bottomRight:[n-1-o.bottomRight[0],o.bottomRight[1]]}}}(s,r)),u={},h=0,d=Object.keys(M);h<d.length;h++)c=d[h],u[c]=M[c].map((function(t){return a.landmarks[t]}));return[2,[{handInViewConfidence:a.handInViewConfidence,boundingBox:a.boundingBox,landmarks:a.landmarks,annotations:u}]]}}))}))},t}();export{K as HandPose,G as load};
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -167,3 +167,3 @@ * you may not use this file except in compliance with the License.

var HandDetector = /** @class */ (function () {
function HandDetector(model, width, height, anchors, iouThreshold, scoreThreshold) {
function HandDetector(model, width, height, anchorsAnnotated, iouThreshold, scoreThreshold) {
this.model = model;

@@ -174,3 +174,3 @@ this.width = width;

this.scoreThreshold = scoreThreshold;
this.anchors = anchors.map(function (anchor) { return [anchor.x_center, anchor.y_center]; });
this.anchors = anchorsAnnotated.map(function (anchor) { return [anchor.x_center, anchor.y_center]; });
this.anchorsTensor = tf.tensor2d(this.anchors);

@@ -195,3 +195,3 @@ this.inputSizeTensor = tf.tensor1d([width, height]);

return tf.tidy(function () {
var landmarks = tf.add(tf.div(rawPalmLandmarks.reshape([-1, 7, 2]), _this.inputSizeTensor), _this.anchors[index]);
var landmarks = tf.add(tf.div(tf.reshape(rawPalmLandmarks, [-1, 7, 2]), _this.inputSizeTensor), _this.anchors[index]);
return tf.mul(landmarks, _this.inputSizeTensor);

@@ -219,4 +219,4 @@ });

}
prediction = batchedPrediction.squeeze();
scores = tf.tidy(function () { return tf.sigmoid(tf.slice(prediction, [0, 0], [-1, 1])).squeeze(); });
prediction = tf.squeeze(batchedPrediction);
scores = tf.tidy(function () { return tf.squeeze(tf.sigmoid(tf.slice(prediction, [0, 0], [-1, 1]))); });
rawBoxes = tf.slice(prediction, [0, 1], [-1, 4]);

@@ -242,3 +242,3 @@ boxes = this.normalizeBoxes(rawBoxes);

rawPalmLandmarks = tf.slice(prediction, [boxIndex, 5], [1, 14]);
palmLandmarks = tf.tidy(function () { return _this.normalizeLandmarks(rawPalmLandmarks, boxIndex).reshape([
palmLandmarks = tf.tidy(function () { return tf.reshape(_this.normalizeLandmarks(rawPalmLandmarks, boxIndex), [
-1, 2

@@ -268,3 +268,3 @@ ]); });

inputWidth = input.shape[2];
image = tf.tidy(function () { return input.resizeBilinear([_this.width, _this.height]).div(255); });
image = tf.tidy(function () { return tf.div(tf.image.resizeBilinear(input, [_this.width, _this.height]), 255); });
return [4 /*yield*/, this.getBoundingBoxes(image)];

@@ -423,12 +423,14 @@ case 1:

var HandPipeline = /** @class */ (function () {
function HandPipeline(boundingBoxDetector, meshDetector, meshWidth, meshHeight, maxContinuousChecks, detectionConfidence) {
// An array of hand bounding boxes.
this.regionsOfInterest = [];
this.runsWithoutHandDetector = 0;
function HandPipeline(boundingBoxDetector
/* MediaPipe model for detecting hand bounding box */ , meshDetector
/* MediaPipe model for detecting hand mesh */ , meshWidth, meshHeight, maxContinuousChecks, detectionConfidence) {
this.boundingBoxDetector = boundingBoxDetector;
this.meshDetector = meshDetector;
this.meshWidth = meshWidth;
this.meshHeight = meshHeight;
this.maxContinuousChecks = maxContinuousChecks;
this.detectionConfidence = detectionConfidence;
this.meshWidth = meshWidth;
this.meshHeight = meshHeight;
// An array of hand bounding boxes.
this.regionsOfInterest = [];
this.runsWithoutHandDetector = 0;
this.maxHandsNumber = 1; // TODO(annxingyuan): Add multi-hand support.

@@ -531,3 +533,3 @@ }

croppedInput = cutBoxFromImageAndResize(box, rotatedImage, [this.meshWidth, this.meshHeight]);
handImage = croppedInput.div(255);
handImage = tf.div(croppedInput, 255);
croppedInput.dispose();

@@ -746,3 +748,3 @@ rotatedImage.dispose();

}
return input.toFloat().expandDims(0);
return tf.expandDims(tf.cast(input, 'float32'));
});

@@ -749,0 +751,0 @@ return [4 /*yield*/, this.pipeline.estimateHand(image)];

/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");

@@ -17,2 +17,2 @@ * you may not use this file except in compliance with the License.

*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@tensorflow/tfjs-converter"),require("@tensorflow/tfjs-core")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-converter","@tensorflow/tfjs-core"],n):n((t=t||self).handpose={},t.tf,t.tf)}(this,(function(t,n,e){"use strict";function o(t,n,e,o){return new(e||(e=Promise))((function(i,r){function s(t){try{u(o.next(t))}catch(t){r(t)}}function a(t){try{u(o.throw(t))}catch(t){r(t)}}function u(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,a)}u((o=o.apply(t,n||[])).next())}))}function i(t,n){var e,o,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(e)throw new TypeError("Generator is already executing.");for(;s;)try{if(e=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)return i;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,o=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=n.call(t,s)}catch(t){r=[6,t],o=0}finally{e=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function r(t){return[Math.abs(t.endPoint[0]-t.startPoint[0]),Math.abs(t.endPoint[1]-t.startPoint[1])]}function s(t){return[t.startPoint[0]+(t.endPoint[0]-t.startPoint[0])/2,t.startPoint[1]+(t.endPoint[1]-t.startPoint[1])/2]}function a(t,n){void 0===n&&(n=1.5);var e=s(t),o=r(t),i=[n*o[0]/2,n*o[1]/2];return{startPoint:[e[0]-i[0],e[1]-i[1]],endPoint:[e[0]+i[0],e[1]+i[1]],palmLandmarks:t.palmLandmarks}}function u(t){var n=s(t),e=r(t),o=Math.max.apply(Math,e)/2;return{startPoint:[n[0]-o,n[1]-o],endPoint:[n[0]+o,n[1]+o],palmLandmarks:t.palmLandmarks}}function d(t,n){var e=[t.endPoint[0]-t.startPoint[0],t.endPoint[1]-t.startPoint[1]],o=[e[0]*n[0],e[1]*n[1]];return{startPoint:[t.startPoint[0]+o[0],t.startPoint[1]+o[1]],endPoint:[t.endPoint[0]+o[0],t.endPoint[1]+o[1]],palmLandmarks:t.palmLandmarks}}var h=function(){function t(t,n,o,i,r,s){this.model=t,this.width=n,this.height=o,this.iouThreshold=r,this.scoreThreshold=s,this.anchors=i.map((function(t){return[t.x_center,t.y_center]})),this.anchorsTensor=e.tensor2d(this.anchors),this.inputSizeTensor=e.tensor1d([n,o]),this.doubleInputSizeTensor=e.tensor1d([2*n,2*o])}return t.prototype.normalizeBoxes=function(t){var n=this;return e.tidy((function(){var o=e.slice(t,[0,0],[-1,2]),i=e.slice(t,[0,2],[-1,2]),r=e.add(e.div(o,n.inputSizeTensor),n.anchorsTensor),s=e.div(i,n.doubleInputSizeTensor),a=e.mul(e.sub(r,s),n.inputSizeTensor),u=e.mul(e.add(r,s),n.inputSizeTensor);return e.concat2d([a,u],1)}))},t.prototype.normalizeLandmarks=function(t,n){var o=this;return e.tidy((function(){var i=e.add(e.div(t.reshape([-1,7,2]),o.inputSizeTensor),o.anchors[n]);return e.mul(i,o.inputSizeTensor)}))},t.prototype.getBoundingBoxes=function(t){return o(this,void 0,void 0,(function(){var n,o,r,s,a,u,d,h,c,f,l,p,m,v,g,P=this;return i(this,(function(i){switch(i.label){case 0:return n=e.tidy((function(){return e.mul(e.sub(t,.5),2)})),"webgl"===e.getBackend()?(r=e.env().get("WEBGL_PACK_DEPTHWISECONV"),e.env().set("WEBGL_PACK_DEPTHWISECONV",!0),o=this.model.predict(n),e.env().set("WEBGL_PACK_DEPTHWISECONV",r)):o=this.model.predict(n),s=o.squeeze(),a=e.tidy((function(){return e.sigmoid(e.slice(s,[0,0],[-1,1])).squeeze()})),u=e.slice(s,[0,1],[-1,4]),d=this.normalizeBoxes(u),h=console.warn,console.warn=function(){},c=e.image.nonMaxSuppression(d,a,1,this.iouThreshold,this.scoreThreshold),console.warn=h,[4,c.array()];case 1:return f=i.sent(),l=[n,o,c,s,d,u,a],0===f.length?(l.forEach((function(t){return t.dispose()})),[2,null]):(p=f[0],m=e.slice(d,[p,0],[1,-1]),v=e.slice(s,[p,5],[1,14]),g=e.tidy((function(){return P.normalizeLandmarks(v,p).reshape([-1,2])})),l.push(v),l.forEach((function(t){return t.dispose()})),[2,{boxes:m,palmLandmarks:g}])}}))}))},t.prototype.estimateHandBounds=function(t){return o(this,void 0,void 0,(function(){var n,o,r,s,a,u,d,h,c=this;return i(this,(function(i){switch(i.label){case 0:return n=t.shape[1],o=t.shape[2],r=e.tidy((function(){return t.resizeBilinear([c.width,c.height]).div(255)})),[4,this.getBoundingBoxes(r)];case 1:return null===(s=i.sent())?(r.dispose(),[2,null]):(a=s.boxes.arraySync(),u=a[0].slice(0,2),d=a[0].slice(2,4),h=s.palmLandmarks.arraySync(),r.dispose(),s.boxes.dispose(),s.palmLandmarks.dispose(),[2,(f={startPoint:u,endPoint:d,palmLandmarks:h},l=[o/this.width,n/this.height],{startPoint:[f.startPoint[0]*l[0],f.startPoint[1]*l[1]],endPoint:[f.endPoint[0]*l[0],f.endPoint[1]*l[1]],palmLandmarks:f.palmLandmarks.map((function(t){return[t[0]*l[0],t[1]*l[1]]}))})])}var f,l}))}))},t}(),c={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]};function f(t,n){var e,o=Math.PI/2-Math.atan2(-(n[1]-t[1]),n[0]-t[0]);return(e=o)-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}var l=function(t,n){return[[1,0,t],[0,1,n],[0,0,1]]};function p(t,n){for(var e=0,o=0;o<t.length;o++)e+=t[o]*n[o];return e}function m(t,n){for(var e=[],o=0;o<t.length;o++)e.push(t[o][n]);return e}function v(t,n){for(var e=[],o=t.length,i=0;i<o;i++){e.push([]);for(var r=0;r<o;r++)e[i].push(p(t[i],m(n,r)))}return e}function g(t,n){var e=Math.cos(t),o=Math.sin(t),i=[[e,-o,0],[o,e,0],[0,0,1]],r=v(l(n[0],n[1]),i);return v(r,l(-n[0],-n[1]))}function P(t,n){return[p(t,n[0]),p(t,n[1])]}var b=[0,-.4],y=[0,-.1],k=[0,5,9,13,17,1,2],x=function(){function t(t,n,e,o,i,r){this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.boundingBoxDetector=t,this.meshDetector=n,this.maxContinuousChecks=i,this.detectionConfidence=r,this.meshWidth=e,this.meshHeight=o,this.maxHandsNumber=1}return t.prototype.getBoxForPalmLandmarks=function(t,n){var e=t.map((function(t){return P(t.concat([1]),n)}));return a(u(d(this.calculateLandmarksBoundingBox(e),b)),3)},t.prototype.getBoxForHandLandmarks=function(t){for(var n=a(u(d(this.calculateLandmarksBoundingBox(t),y)),1.65),e=[],o=0;o<k.length;o++)e.push(t[k[o]].slice(0,2));return n.palmLandmarks=e,n},t.prototype.transformRawCoords=function(t,n,e,o){var i,a,u,d,h=this,c=r(n),f=[c[0]/this.meshWidth,c[1]/this.meshHeight],l=t.map((function(t){return[f[0]*(t[0]-h.meshWidth/2),f[1]*(t[1]-h.meshHeight/2),t[2]]})),m=g(e,[0,0]),v=l.map((function(t){return P(t,m).concat([t[2]])})),b=(a=[[(i=o)[0][0],i[1][0]],[i[0][1],i[1][1]]],u=[i[0][2],i[1][2]],d=[-p(a[0],u),-p(a[1],u)],[a[0].concat(d[0]),a[1].concat(d[1]),[0,0,1]]),y=s(n).concat([1]),k=[p(y,b[0]),p(y,b[1])];return v.map((function(t){return[t[0]+k[0],t[1]+k[1],t[2]]}))},t.prototype.estimateHand=function(t){return o(this,void 0,void 0,(function(){var n,o,r,a,u,d,h,c,l,p,m,v,P,b,y,k,x,w,B,L;return i(this,(function(i){switch(i.label){case 0:return!0!==(n=this.shouldUpdateRegionsOfInterest())?[3,2]:[4,this.boundingBoxDetector.estimateHandBounds(t)];case 1:return null===(o=i.sent())?(t.dispose(),this.regionsOfInterest=[],[2,null]):(this.updateRegionsOfInterest(o,!0),this.runsWithoutHandDetector=0,[3,3]);case 2:this.runsWithoutHandDetector++,i.label=3;case 3:return r=this.regionsOfInterest[0],a=f(r.palmLandmarks[0],r.palmLandmarks[2]),u=s(r),d=[u[0]/t.shape[2],u[1]/t.shape[1]],h=e.image.rotateWithOffset(t,a,0,d),c=g(-a,u),l=!0===n?this.getBoxForPalmLandmarks(r.palmLandmarks,c):r,p=function(t,n,o){var i=n.shape[1],r=n.shape[2],s=[[t.startPoint[1]/i,t.startPoint[0]/r,t.endPoint[1]/i,t.endPoint[0]/r]];return e.image.cropAndResize(n,s,[0],o)}(l,h,[this.meshWidth,this.meshHeight]),m=p.div(255),p.dispose(),h.dispose(),"webgl"===e.getBackend()?(P=e.env().get("WEBGL_PACK_DEPTHWISECONV"),e.env().set("WEBGL_PACK_DEPTHWISECONV",!0),v=this.meshDetector.predict(m),e.env().set("WEBGL_PACK_DEPTHWISECONV",P)):v=this.meshDetector.predict(m),b=v[0],y=v[1],m.dispose(),k=b.dataSync()[0],b.dispose(),k<this.detectionConfidence?(y.dispose(),this.regionsOfInterest=[],[2,null]):(x=e.reshape(y,[-1,3]),w=x.arraySync(),y.dispose(),x.dispose(),B=this.transformRawCoords(w,l,a,c),L=this.getBoxForHandLandmarks(B),this.updateRegionsOfInterest(L,!1),[2,{landmarks:B,handInViewConfidence:k,boundingBox:{topLeft:L.startPoint,bottomRight:L.endPoint}}])}}))}))},t.prototype.calculateLandmarksBoundingBox=function(t){var n=t.map((function(t){return t[0]})),e=t.map((function(t){return t[1]}));return{startPoint:[Math.min.apply(Math,n),Math.min.apply(Math,e)],endPoint:[Math.max.apply(Math,n),Math.max.apply(Math,e)]}},t.prototype.updateRegionsOfInterest=function(t,n){if(n)this.regionsOfInterest=[t];else{var e=this.regionsOfInterest[0],o=0;if(null!=e&&null!=e.startPoint){var i=t.startPoint,r=i[0],s=i[1],a=t.endPoint,u=a[0],d=a[1],h=e.startPoint,c=h[0],f=h[1],l=e.endPoint,p=l[0],m=l[1],v=Math.max(r,c),g=Math.max(s,f),P=(Math.min(u,p)-v)*(Math.min(d,m)-g);o=P/((u-r)*(d-s)+(p-c)*(m-s)-P)}this.regionsOfInterest[0]=o>.8?e:t}},t.prototype.shouldUpdateRegionsOfInterest=function(){return this.regionsOfInterest.length!==this.maxHandsNumber||this.runsWithoutHandDetector>=this.maxContinuousChecks},t}();function w(){return o(this,void 0,void 0,(function(){return i(this,(function(t){return"https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",[2,n.loadGraphModel("https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",{fromTFHub:!0})]}))}))}function B(){return o(this,void 0,void 0,(function(){return i(this,(function(t){return"https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",[2,n.loadGraphModel("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",{fromTFHub:!0})]}))}))}function L(){return o(this,void 0,void 0,(function(){return i(this,(function(t){return[2,e.util.fetch("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1/anchors.json?tfjs-format=file").then((function(t){return t.json()}))]}))}))}var I=function(){function t(t){this.pipeline=t}return t.getAnnotations=function(){return c},t.prototype.estimateHands=function(t,n){return void 0===n&&(n=!1),o(this,void 0,void 0,(function(){var o,r,s,a,u,d,h,f,l;return i(this,(function(i){switch(i.label){case 0:return o=function(t){return t instanceof e.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),r=o[1],s=e.tidy((function(){return t instanceof e.Tensor||(t=e.browser.fromPixels(t)),t.toFloat().expandDims(0)})),[4,this.pipeline.estimateHand(s)];case 1:if(a=i.sent(),s.dispose(),null===a)return[2,[]];for(u=a,!0===n&&(u=function(t,n){var e=t.handInViewConfidence,o=t.landmarks,i=t.boundingBox;return{handInViewConfidence:e,landmarks:o.map((function(t){return[n-1-t[0],t[1],t[2]]})),boundingBox:{topLeft:[n-1-i.topLeft[0],i.topLeft[1]],bottomRight:[n-1-i.bottomRight[0],i.bottomRight[1]]}}}(a,r)),d={},h=0,f=Object.keys(c);h<f.length;h++)l=f[h],d[l]=c[l].map((function(t){return u.landmarks[t]}));return[2,[{handInViewConfidence:u.handInViewConfidence,boundingBox:u.boundingBox,landmarks:u.landmarks,annotations:d}]]}}))}))},t}();t.HandPose=I,t.load=function(t){var n=void 0===t?{}:t,e=n.maxContinuousChecks,r=void 0===e?1/0:e,s=n.detectionConfidence,a=void 0===s?.8:s,u=n.iouThreshold,d=void 0===u?.3:u,c=n.scoreThreshold,f=void 0===c?.5:c;return o(this,void 0,void 0,(function(){var t,n,e,o,s,u;return i(this,(function(i){switch(i.label){case 0:return[4,Promise.all([L(),w(),B()])];case 1:return t=i.sent(),n=t[0],e=t[1],o=t[2],s=new h(e,256,256,n,d,f),u=new x(s,o,256,256,r,a),[2,new I(u)]}}))}))},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@tensorflow/tfjs-converter"),require("@tensorflow/tfjs-core")):"function"==typeof define&&define.amd?define(["exports","@tensorflow/tfjs-converter","@tensorflow/tfjs-core"],n):n((t=t||self).handpose={},t.tf,t.tf)}(this,(function(t,n,e){"use strict";function i(t,n,e,i){return new(e||(e=Promise))((function(o,r){function s(t){try{u(i.next(t))}catch(t){r(t)}}function a(t){try{u(i.throw(t))}catch(t){r(t)}}function u(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,a)}u((i=i.apply(t,n||[])).next())}))}function o(t,n){var e,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(e)throw new TypeError("Generator is already executing.");for(;s;)try{if(e=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]<o[3])){s.label=r[1];break}if(6===r[0]&&s.label<o[1]){s.label=o[1],o=r;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(r);break}o[2]&&s.ops.pop(),s.trys.pop();continue}r=n.call(t,s)}catch(t){r=[6,t],i=0}finally{e=o=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function r(t){return[Math.abs(t.endPoint[0]-t.startPoint[0]),Math.abs(t.endPoint[1]-t.startPoint[1])]}function s(t){return[t.startPoint[0]+(t.endPoint[0]-t.startPoint[0])/2,t.startPoint[1]+(t.endPoint[1]-t.startPoint[1])/2]}function a(t,n){void 0===n&&(n=1.5);var e=s(t),i=r(t),o=[n*i[0]/2,n*i[1]/2];return{startPoint:[e[0]-o[0],e[1]-o[1]],endPoint:[e[0]+o[0],e[1]+o[1]],palmLandmarks:t.palmLandmarks}}function u(t){var n=s(t),e=r(t),i=Math.max.apply(Math,e)/2;return{startPoint:[n[0]-i,n[1]-i],endPoint:[n[0]+i,n[1]+i],palmLandmarks:t.palmLandmarks}}function d(t,n){var e=[t.endPoint[0]-t.startPoint[0],t.endPoint[1]-t.startPoint[1]],i=[e[0]*n[0],e[1]*n[1]];return{startPoint:[t.startPoint[0]+i[0],t.startPoint[1]+i[1]],endPoint:[t.endPoint[0]+i[0],t.endPoint[1]+i[1]],palmLandmarks:t.palmLandmarks}}var h=function(){function t(t,n,i,o,r,s){this.model=t,this.width=n,this.height=i,this.iouThreshold=r,this.scoreThreshold=s,this.anchors=o.map((function(t){return[t.x_center,t.y_center]})),this.anchorsTensor=e.tensor2d(this.anchors),this.inputSizeTensor=e.tensor1d([n,i]),this.doubleInputSizeTensor=e.tensor1d([2*n,2*i])}return t.prototype.normalizeBoxes=function(t){var n=this;return e.tidy((function(){var i=e.slice(t,[0,0],[-1,2]),o=e.slice(t,[0,2],[-1,2]),r=e.add(e.div(i,n.inputSizeTensor),n.anchorsTensor),s=e.div(o,n.doubleInputSizeTensor),a=e.mul(e.sub(r,s),n.inputSizeTensor),u=e.mul(e.add(r,s),n.inputSizeTensor);return e.concat2d([a,u],1)}))},t.prototype.normalizeLandmarks=function(t,n){var i=this;return e.tidy((function(){var o=e.add(e.div(e.reshape(t,[-1,7,2]),i.inputSizeTensor),i.anchors[n]);return e.mul(o,i.inputSizeTensor)}))},t.prototype.getBoundingBoxes=function(t){return i(this,void 0,void 0,(function(){var n,i,r,s,a,u,d,h,c,f,l,p,m,v,g,P=this;return o(this,(function(o){switch(o.label){case 0:return n=e.tidy((function(){return e.mul(e.sub(t,.5),2)})),"webgl"===e.getBackend()?(r=e.env().get("WEBGL_PACK_DEPTHWISECONV"),e.env().set("WEBGL_PACK_DEPTHWISECONV",!0),i=this.model.predict(n),e.env().set("WEBGL_PACK_DEPTHWISECONV",r)):i=this.model.predict(n),s=e.squeeze(i),a=e.tidy((function(){return e.squeeze(e.sigmoid(e.slice(s,[0,0],[-1,1])))})),u=e.slice(s,[0,1],[-1,4]),d=this.normalizeBoxes(u),h=console.warn,console.warn=function(){},c=e.image.nonMaxSuppression(d,a,1,this.iouThreshold,this.scoreThreshold),console.warn=h,[4,c.array()];case 1:return f=o.sent(),l=[n,i,c,s,d,u,a],0===f.length?(l.forEach((function(t){return t.dispose()})),[2,null]):(p=f[0],m=e.slice(d,[p,0],[1,-1]),v=e.slice(s,[p,5],[1,14]),g=e.tidy((function(){return e.reshape(P.normalizeLandmarks(v,p),[-1,2])})),l.push(v),l.forEach((function(t){return t.dispose()})),[2,{boxes:m,palmLandmarks:g}])}}))}))},t.prototype.estimateHandBounds=function(t){return i(this,void 0,void 0,(function(){var n,i,r,s,a,u,d,h,c=this;return o(this,(function(o){switch(o.label){case 0:return n=t.shape[1],i=t.shape[2],r=e.tidy((function(){return e.div(e.image.resizeBilinear(t,[c.width,c.height]),255)})),[4,this.getBoundingBoxes(r)];case 1:return null===(s=o.sent())?(r.dispose(),[2,null]):(a=s.boxes.arraySync(),u=a[0].slice(0,2),d=a[0].slice(2,4),h=s.palmLandmarks.arraySync(),r.dispose(),s.boxes.dispose(),s.palmLandmarks.dispose(),[2,(f={startPoint:u,endPoint:d,palmLandmarks:h},l=[i/this.width,n/this.height],{startPoint:[f.startPoint[0]*l[0],f.startPoint[1]*l[1]],endPoint:[f.endPoint[0]*l[0],f.endPoint[1]*l[1]],palmLandmarks:f.palmLandmarks.map((function(t){return[t[0]*l[0],t[1]*l[1]]}))})])}var f,l}))}))},t}(),c={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]};function f(t,n){var e,i=Math.PI/2-Math.atan2(-(n[1]-t[1]),n[0]-t[0]);return(e=i)-2*Math.PI*Math.floor((e+Math.PI)/(2*Math.PI))}var l=function(t,n){return[[1,0,t],[0,1,n],[0,0,1]]};function p(t,n){for(var e=0,i=0;i<t.length;i++)e+=t[i]*n[i];return e}function m(t,n){for(var e=[],i=0;i<t.length;i++)e.push(t[i][n]);return e}function v(t,n){for(var e=[],i=t.length,o=0;o<i;o++){e.push([]);for(var r=0;r<i;r++)e[o].push(p(t[o],m(n,r)))}return e}function g(t,n){var e=Math.cos(t),i=Math.sin(t),o=[[e,-i,0],[i,e,0],[0,0,1]],r=v(l(n[0],n[1]),o);return v(r,l(-n[0],-n[1]))}function P(t,n){return[p(t,n[0]),p(t,n[1])]}var b=[0,-.4],y=[0,-.1],k=[0,5,9,13,17,1,2],x=function(){function t(t,n,e,i,o,r){this.boundingBoxDetector=t,this.meshDetector=n,this.meshWidth=e,this.meshHeight=i,this.maxContinuousChecks=o,this.detectionConfidence=r,this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.maxHandsNumber=1}return t.prototype.getBoxForPalmLandmarks=function(t,n){var e=t.map((function(t){return P(t.concat([1]),n)}));return a(u(d(this.calculateLandmarksBoundingBox(e),b)),3)},t.prototype.getBoxForHandLandmarks=function(t){for(var n=a(u(d(this.calculateLandmarksBoundingBox(t),y)),1.65),e=[],i=0;i<k.length;i++)e.push(t[k[i]].slice(0,2));return n.palmLandmarks=e,n},t.prototype.transformRawCoords=function(t,n,e,i){var o,a,u,d,h=this,c=r(n),f=[c[0]/this.meshWidth,c[1]/this.meshHeight],l=t.map((function(t){return[f[0]*(t[0]-h.meshWidth/2),f[1]*(t[1]-h.meshHeight/2),t[2]]})),m=g(e,[0,0]),v=l.map((function(t){return P(t,m).concat([t[2]])})),b=(a=[[(o=i)[0][0],o[1][0]],[o[0][1],o[1][1]]],u=[o[0][2],o[1][2]],d=[-p(a[0],u),-p(a[1],u)],[a[0].concat(d[0]),a[1].concat(d[1]),[0,0,1]]),y=s(n).concat([1]),k=[p(y,b[0]),p(y,b[1])];return v.map((function(t){return[t[0]+k[0],t[1]+k[1],t[2]]}))},t.prototype.estimateHand=function(t){return i(this,void 0,void 0,(function(){var n,i,r,a,u,d,h,c,l,p,m,v,P,b,y,k,x,w,B,L;return o(this,(function(o){switch(o.label){case 0:return!0!==(n=this.shouldUpdateRegionsOfInterest())?[3,2]:[4,this.boundingBoxDetector.estimateHandBounds(t)];case 1:return null===(i=o.sent())?(t.dispose(),this.regionsOfInterest=[],[2,null]):(this.updateRegionsOfInterest(i,!0),this.runsWithoutHandDetector=0,[3,3]);case 2:this.runsWithoutHandDetector++,o.label=3;case 3:return r=this.regionsOfInterest[0],a=f(r.palmLandmarks[0],r.palmLandmarks[2]),u=s(r),d=[u[0]/t.shape[2],u[1]/t.shape[1]],h=e.image.rotateWithOffset(t,a,0,d),c=g(-a,u),l=!0===n?this.getBoxForPalmLandmarks(r.palmLandmarks,c):r,p=function(t,n,i){var o=n.shape[1],r=n.shape[2],s=[[t.startPoint[1]/o,t.startPoint[0]/r,t.endPoint[1]/o,t.endPoint[0]/r]];return e.image.cropAndResize(n,s,[0],i)}(l,h,[this.meshWidth,this.meshHeight]),m=e.div(p,255),p.dispose(),h.dispose(),"webgl"===e.getBackend()?(P=e.env().get("WEBGL_PACK_DEPTHWISECONV"),e.env().set("WEBGL_PACK_DEPTHWISECONV",!0),v=this.meshDetector.predict(m),e.env().set("WEBGL_PACK_DEPTHWISECONV",P)):v=this.meshDetector.predict(m),b=v[0],y=v[1],m.dispose(),k=b.dataSync()[0],b.dispose(),k<this.detectionConfidence?(y.dispose(),this.regionsOfInterest=[],[2,null]):(x=e.reshape(y,[-1,3]),w=x.arraySync(),y.dispose(),x.dispose(),B=this.transformRawCoords(w,l,a,c),L=this.getBoxForHandLandmarks(B),this.updateRegionsOfInterest(L,!1),[2,{landmarks:B,handInViewConfidence:k,boundingBox:{topLeft:L.startPoint,bottomRight:L.endPoint}}])}}))}))},t.prototype.calculateLandmarksBoundingBox=function(t){var n=t.map((function(t){return t[0]})),e=t.map((function(t){return t[1]}));return{startPoint:[Math.min.apply(Math,n),Math.min.apply(Math,e)],endPoint:[Math.max.apply(Math,n),Math.max.apply(Math,e)]}},t.prototype.updateRegionsOfInterest=function(t,n){if(n)this.regionsOfInterest=[t];else{var e=this.regionsOfInterest[0],i=0;if(null!=e&&null!=e.startPoint){var o=t.startPoint,r=o[0],s=o[1],a=t.endPoint,u=a[0],d=a[1],h=e.startPoint,c=h[0],f=h[1],l=e.endPoint,p=l[0],m=l[1],v=Math.max(r,c),g=Math.max(s,f),P=(Math.min(u,p)-v)*(Math.min(d,m)-g);i=P/((u-r)*(d-s)+(p-c)*(m-s)-P)}this.regionsOfInterest[0]=i>.8?e:t}},t.prototype.shouldUpdateRegionsOfInterest=function(){return this.regionsOfInterest.length!==this.maxHandsNumber||this.runsWithoutHandDetector>=this.maxContinuousChecks},t}();function w(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return"https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",[2,n.loadGraphModel("https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",{fromTFHub:!0})]}))}))}function B(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return"https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",[2,n.loadGraphModel("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",{fromTFHub:!0})]}))}))}function L(){return i(this,void 0,void 0,(function(){return o(this,(function(t){return[2,e.util.fetch("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1/anchors.json?tfjs-format=file").then((function(t){return t.json()}))]}))}))}var I=function(){function t(t){this.pipeline=t}return t.getAnnotations=function(){return c},t.prototype.estimateHands=function(t,n){return void 0===n&&(n=!1),i(this,void 0,void 0,(function(){var i,r,s,a,u,d,h,f,l;return o(this,(function(o){switch(o.label){case 0:return i=function(t){return t instanceof e.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),r=i[1],s=e.tidy((function(){return t instanceof e.Tensor||(t=e.browser.fromPixels(t)),e.expandDims(e.cast(t,"float32"))})),[4,this.pipeline.estimateHand(s)];case 1:if(a=o.sent(),s.dispose(),null===a)return[2,[]];for(u=a,!0===n&&(u=function(t,n){var e=t.handInViewConfidence,i=t.landmarks,o=t.boundingBox;return{handInViewConfidence:e,landmarks:i.map((function(t){return[n-1-t[0],t[1],t[2]]})),boundingBox:{topLeft:[n-1-o.topLeft[0],o.topLeft[1]],bottomRight:[n-1-o.bottomRight[0],o.bottomRight[1]]}}}(a,r)),d={},h=0,f=Object.keys(c);h<f.length;h++)l=f[h],d[l]=c[l].map((function(t){return u.landmarks[t]}));return[2,[{handInViewConfidence:u.handInViewConfidence,boundingBox:u.boundingBox,landmarks:u.landmarks,annotations:d}]]}}))}))},t}();t.HandPose=I,t.load=function(t){var n=void 0===t?{}:t,e=n.maxContinuousChecks,r=void 0===e?1/0:e,s=n.detectionConfidence,a=void 0===s?.8:s,u=n.iouThreshold,d=void 0===u?.3:u,c=n.scoreThreshold,f=void 0===c?.5:c;return i(this,void 0,void 0,(function(){var t,n,e,i,s,u;return o(this,(function(o){switch(o.label){case 0:return[4,Promise.all([L(),w(),B()])];case 1:return t=o.sent(),n=t[0],e=t[1],i=t[2],s=new h(e,256,256,n,d,f),u=new x(s,i,256,256,r,a),[2,new I(u)]}}))}))},Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -172,3 +172,3 @@ "use strict";

}
return input.toFloat().expandDims(0);
return tf.expandDims(tf.cast(input, 'float32'));
});

@@ -175,0 +175,0 @@ return [4 /*yield*/, this.pipeline.estimateHand(image)];

@@ -67,12 +67,14 @@ "use strict";

var HandPipeline = /** @class */ (function () {
function HandPipeline(boundingBoxDetector, meshDetector, meshWidth, meshHeight, maxContinuousChecks, detectionConfidence) {
// An array of hand bounding boxes.
this.regionsOfInterest = [];
this.runsWithoutHandDetector = 0;
function HandPipeline(boundingBoxDetector
/* MediaPipe model for detecting hand bounding box */ , meshDetector
/* MediaPipe model for detecting hand mesh */ , meshWidth, meshHeight, maxContinuousChecks, detectionConfidence) {
this.boundingBoxDetector = boundingBoxDetector;
this.meshDetector = meshDetector;
this.meshWidth = meshWidth;
this.meshHeight = meshHeight;
this.maxContinuousChecks = maxContinuousChecks;
this.detectionConfidence = detectionConfidence;
this.meshWidth = meshWidth;
this.meshHeight = meshHeight;
// An array of hand bounding boxes.
this.regionsOfInterest = [];
this.runsWithoutHandDetector = 0;
this.maxHandsNumber = 1; // TODO(annxingyuan): Add multi-hand support.

@@ -175,3 +177,3 @@ }

croppedInput = box_1.cutBoxFromImageAndResize(box, rotatedImage, [this.meshWidth, this.meshHeight]);
handImage = croppedInput.div(255);
handImage = tf.div(croppedInput, 255);
croppedInput.dispose();

@@ -178,0 +180,0 @@ rotatedImage.dispose();

@@ -5,4 +5,4 @@ "use strict";

// This code is auto-generated, do not modify this file!
var version = '0.0.6';
var version = '0.0.7';
exports.version = version;
//# sourceMappingURL=version.js.map
{
"name": "@tensorflow-models/handpose",
"version": "0.0.6",
"version": "0.0.7",
"description": "Pretrained hand detection model",

@@ -16,4 +16,5 @@ "main": "dist/index.js",

"peerDependencies": {
"@tensorflow/tfjs-converter": "^2.1.0",
"@tensorflow/tfjs-core": "^2.1.0"
"@tensorflow/tfjs-converter": "^3.0.0",
"@tensorflow/tfjs-core": "^3.0.0",
"@tensorflow/tfjs-backend-webgl": "^3.0.0"
},

@@ -24,5 +25,6 @@ "devDependencies": {

"@rollup/plugin-typescript": "^3.0.0",
"@tensorflow/tfjs-converter": "^2.1.0",
"@tensorflow/tfjs-core": "^2.1.0",
"@tensorflow/tfjs-backend-cpu": "^2.1.0",
"@tensorflow/tfjs-converter": "^3.0.0",
"@tensorflow/tfjs-core": "^3.0.0",
"@tensorflow/tfjs-backend-cpu": "^3.0.0",
"@tensorflow/tfjs-backend-webgl": "^3.0.0",
"@types/jasmine": "~2.8.8",

@@ -41,6 +43,7 @@ "babel-core": "~6.26.0",

"scripts": {
"build": "rimraf dist && tsc",
"bundle": "rollup -c",
"build": "rimraf dist && tsc && yarn bundle",
"publish-local": "yarn build && rollup -c && yalc publish",
"test": "yarn build && ts-node --skip-ignore run_tests.ts",
"build-npm": "yarn build && rollup -c --npm",
"test": "ts-node --skip-ignore --project tsconfig.test.json run_tests.ts",
"build-npm": "yarn build && yarn bundle",
"lint": "tslint -p . -t verbose",

@@ -53,2 +56,2 @@ "publish-demo": "./scripts/publish-demo.sh"

}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc