2016-10-07 15:48:53 +00:00
|
|
|
var DOM={body:$("body"),canvas:$("canvas"),imageLoader:$("#image-loader")},Controller=new dat.GUI,_CAN=DOM.canvas;_CAN.width=_CAN.height=1E3;
|
2016-11-02 18:15:20 +00:00
|
|
|
var _CON=_CAN.getContext("2d"),iL,filterManager,process=function(){},exec=!1,last,trackerTask,init=function(){this.src="front/male/1.jpg";Controller.addFolder("Source Picture");Controller.add(this,"src",this._images).listen();last=this.src},zones,track={track:function(){zones=[];trackerTask=tracking.track(_CAN,tracker)}},tracker=new tracking.ObjectTracker(["face","eye","mouth"]);tracker.setStepSize(1.9);Controller.addFolder("Tracking.js");Controller.add(track,"track");
|
|
|
|
tracker.on("track",function(b){b.data.forEach(function(a){zones.push({x:a.x/_CAN.width,y:a.y/_CAN.height,w:a.width/_CAN.width,h:a.height/_CAN.height})});log("Recognition done","[Tracking.js]");process.bind(DOM.imageLoader)()});
|
|
|
|
process=function(){if(this instanceof HTMLImageElement){console.time("PROCESS");this.src!=last&&(zones=[],exec=!1,last=this.src);exec||(this.defaultWidth=this.width,this.defaultHeight=this.height,log("Image copied","[Canvas]"),exec=!0);_CON.clearRect(0,0,_CAN.width,_CAN.height);filterManager.get("resolution").apply();filterManager.get("contrast").apply();filterManager.get("sobel").apply();filterManager.get("gaussian").apply();filterManager.get("canny").apply();for(var b in zones){var a=zones[b].x*
|
|
|
|
_CAN.width,c=zones[b].y*_CAN.height,d=zones[b].w*_CAN.width,e=zones[b].h*_CAN.height;_CON.beginPath();_CON.moveTo(a,c);_CON.lineTo(a,c+e);_CON.lineTo(a+d,c+e);_CON.lineTo(a+d,c);_CON.lineTo(a,c);_CON.lineWidth=5;_CON.strokeStyle="#f00";_CON.stroke()}console.timeEnd("PROCESS")}};filterManager=new ReactiveFilterManager(DOM.imageLoader,_CAN,process);filterManager.add("resolution",reactiveResolution);filterManager.add("contrast",reactiveContrast);filterManager.add("sobel",reactiveSobel);
|
|
|
|
filterManager.add("gaussian",reactiveGaussianBlur);filterManager.add("canny",reactiveCanny);Controller.addFolder("Image Resolution");Controller.add(filterManager.get("resolution"),"width",0,2).step(.1).listen();Controller.add(filterManager.get("resolution"),"height",0,2).step(.1).listen();Controller.addFolder("Basic Image Processing");Controller.add(filterManager.get("contrast"),"contrast",0,100).listen();Controller.addFolder("Gaussian Blur");
|
|
|
|
Controller.add(filterManager.get("gaussian"),"sigma",0,10).step(.5).listen();Controller.add(filterManager.get("gaussian"),"radius",1,11).step(1).listen();Controller.addFolder("Convolution Filters");Controller.add(filterManager.get("sobel"),"sobelActive").listen();Controller.add(filterManager.get("canny"),"canny_radius").listen();Controller.remember(filterManager.get("resolution"));Controller.remember(filterManager.get("contrast"));Controller.remember(filterManager.get("sobel"));Controller.remember(filterManager.get("canny"));
|
|
|
|
Controller.remember(filterManager.get("gaussian"));Controller.__save_row.children[2].addEventListener("click",function(b){Controller.save();try{JSON.stringify(Controller.load.remembered)}catch(a){log("Error parsing/storing data.","[PermanentStorage]")}},!1);iL=new ImageLoader(DOM.imageLoader,init,process);
|