-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.Gest.min.js
17 lines (17 loc) · 2.85 KB
/
jquery.Gest.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
!function(a){a.fn.Gest=function(){function t(){return!!(navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia)}function e(){i()}function i(){o(),n(),r(),d()}function o(){for(var t=0;3>t;t++){var e={visual:a("#note"+t)[0]}
e.area={x:U[t],y:0,width:e.visual.width,height:160},O.push(e)}}function n(){for(var t=3;6>t;t++){var e={visual:a("#note"+t)[0]}
e.area={x:p[t-3],y:160,width:e.visual.width,height:160},j.push(e)}console.log(j)}function r(){for(var t=6;9>t;t++){var e={visual:a("#note"+t)[0]}
e.area={x:x[t-6],y:330,width:e.visual.width,height:160},z.push(e)}console.log(z)}function d(){a(I).show(),a(k).show(),a("#grid").show(),a("#message").hide(),a("#description").show(),s()}function s(){u(),h(),c(),f(),w(),b=setTimeout(s,20)}function u(){D.drawImage(y,0,0,y.width,y.height)}function h(){var a=I.width,t=I.height,e=D.getImageData(0,0,a,t)
M||(M=D.getImageData(0,0,a,t))
var i=D.createImageData(a,t)
v(i.data,e.data,M.data),G.putImageData(i,0,0),M=e}function g(a){return(a^a>>31)-(a>>31)}function l(a){return a>21?255:0}function v(a,t,e){if(t.length!=e.length)return null
for(var i=0;i<.25*t.length;){var o=(t[4*i]+t[4*i+1]+t[4*i+2])/3,n=(e[4*i]+e[4*i+1]+e[4*i+2])/3,r=l(g(o-n))
a[4*i]=r,a[4*i+1]=r,a[4*i+2]=r,a[4*i+3]=255,++i}}function c(){for(var t=0;3>t;++t){for(var e=G.getImageData(O[t].area.x,O[t].area.y,O[t].area.width,O[t].area.height),i=0,o=0;i<.25*e.data.length;)o+=(e.data[4*i]+e.data[4*i+1]+e.data[4*i+2])/3,++i
o=Math.round(o/(.25*e.data.length)),o>10&&(console.log(t),O[t].visual.style.display="block",a(O[t].visual).fadeOut())}}function f(){for(var t=3;6>t;++t){for(var e=G.getImageData(j[t-3].area.x,j[t-3].area.y,j[t-3].area.width,j[t-3].area.height),i=0,o=0;i<.25*e.data.length;)o+=(e.data[4*i]+e.data[4*i+1]+e.data[4*i+2])/3,++i
o=Math.round(o/(.25*e.data.length)),o>10&&(console.log(t),j[t-3].visual.style.display="block",a(j[t-3].visual).fadeOut())}}function w(){for(var t=6;9>t;++t){for(var e=G.getImageData(z[t-6].area.x,z[t-6].area.y,z[t-6].area.width,z[t-6].area.height),i=0,o=0;i<.25*e.data.length;)o+=(e.data[4*i]+e.data[4*i+1]+e.data[4*i+2])/3,++i
o=Math.round(o/(.25*e.data.length)),o>5&&(console.log(t),z[t-6].visual.style.display="block",a(z[t-6].visual).fadeOut())}}if(!t())return a("#info").show(),a("#message").hide(),a("#video-demo").show(),a("#video-demo")[0].play(),void 0
a("#info").hide(),a("#message").show()
var m=function(a){alert("Webcam error!",a)},y=a("#webcam")[0]
navigator.getUserMedia?navigator.getUserMedia({audio:!1,video:!0},function(a){y.src=a,initialize()},m):navigator.webkitGetUserMedia&&navigator.webkitGetUserMedia({audio:!1,video:!0},function(a){y.src=window.webkitURL.createObjectURL(a),e()},m)
var b,M,U=[0,218,430],p=[0,218,430],x=[0,218,430],I=a("#canvas-source")[0],k=a("#canvas-blended")[0],D=I.getContext("2d"),G=k.getContext("2d"),O=[],j=[],z=[]
D.translate(I.width,0),D.scale(-1,1)}}(jQuery)