2016-11-04 17:44:29 +00:00
var DOM = { body : $ ( "body" ) , canvas : $ ( "canvas" ) , imageLoader : $ ( "#image-loader" ) } , _CAN = DOM . canvas ; _CAN . width = _CAN . height = 1E3 ; var _CON = _CAN . getContext ( "2d" ) , iL , filterManager , process = function ( ) { } , exec = ! 1 , last , featureTrackerTask , trackerCallback , Controller , CFolder = { } , init , zones = { feature : [ ] } , track , featureTracker , initialized = ! 1 , ControllerRememberer = new PermanentStorage ;
ControllerRememberer . fetch ( function ( f ) { log ( "Preset loaded." , "[PermanentStorage]" ) ; Controller = new dat . GUI ( { load : JSON . parse ( f ) , preset : "default" } ) ; init = function ( ) { last = this . src = "front/male/1.jpg" ; initialized = ! 0 ; CFolder . src = Controller . addFolder ( "Source Picture" ) ; Controller . remember ( this ) ; CFolder . src . add ( this , "src" , this . _images ) . listen ( ) } ; zones . feature = [ ] ; track = { trackFeatures : function ( ) { LOADER . start ( ) ; zones . feature = [ ] ; featureTrackerTask = tracking . track ( _CAN , featureTracker ) ; LOADER . stop ( ) } } ; featureTracker =
new tracking . ObjectTracker ( [ "eye" , "mouth" ] ) ; featureTracker . setInitialScale ( 1 ) ; featureTracker . setStepSize ( 1.2 ) ; featureTracker . setEdgesDensity ( . 1 ) ; trackerCallback = function ( a , c ) { zones [ a ] . length = 0 ; c . data . forEach ( function ( b ) { zones [ a ] . push ( { x : b . x / _CAN . width , y : b . y / _CAN . height , w : b . width / _CAN . width , h : b . height / _CAN . height } ) } ) ; 0 < zones [ a ] . length ? log ( a + " recognition done" , "[Tracking.js]" ) : log ( a + " recognition failed" , "[Tracking.js]" ) ; process . apply ( DOM . imageLoader ) } ; featureTracker . on ( "track" , function ( a ) { return trackerCallback . apply ( this ,
[ "feature" , a ] ) } ) ; LOADER . init ( ) ; process = function ( ) { if ( initialized && this instanceof HTMLImageElement ) { console . time ( "PROCESS" ) ; LOADER . start ( ) ; this . src != last && ( reactiveFaceTracking . zones = [ ] , zones . feature = [ ] , 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 ( "grayscale" ) . apply ( ) ; filterManager . get ( "sobel" ) . apply ( ) ;
filterManager . get ( "gaussian" ) . apply ( ) ; filterManager . get ( "canny" ) . apply ( ) ; var a , c , b , d , e ; for ( a in zones . feature ) c = zones . feature [ a ] . x * _CAN . width , b = zones . feature [ a ] . y * _CAN . height , d = zones . feature [ a ] . w * _CAN . width , e = zones . feature [ a ] . h * _CAN . height , _CON . lineWidth = 5 , _CON . strokeStyle = "#f00" , _CON . strokeRect ( c , b , d , e ) ; for ( a in reactiveFaceTracking . zones ) c = reactiveFaceTracking . zones [ a ] . x * _CAN . width , b = reactiveFaceTracking . zones [ a ] . y * _CAN . height , d = reactiveFaceTracking . zones [ a ] . w * _CAN . width , e = reactiveFaceTracking . zones [ a ] . h *
_CAN . height , _CON . lineWidth = 5 , _CON . strokeStyle = "#ff0" , _CON . strokeRect ( c , b , d , e ) ; console . timeEnd ( "PROCESS" ) ; LOADER . stop ( ) } } ; filterManager = new ReactiveFilterManager ( DOM . imageLoader , _CAN , process ) ; filterManager . add ( "face_tracking" , reactiveFaceTracking ) ; filterManager . add ( "resolution" , reactiveResolution ) ; filterManager . add ( "contrast" , reactiveContrast ) ; filterManager . add ( "grayscale" , reactiveGrayscale ) ; filterManager . add ( "sobel" , reactiveSobel ) ; filterManager . add ( "gaussian" , reactiveGaussianBlur ) ; filterManager . add ( "canny" ,
reactiveCanny ) ; filterManager . add ( "haar_face" , reactiveHaarFace ) ; Controller . remember ( filterManager . get ( "face_tracking" ) ) ; Controller . remember ( filterManager . get ( "resolution" ) ) ; Controller . remember ( filterManager . get ( "contrast" ) ) ; Controller . remember ( filterManager . get ( "grayscale" ) ) ; Controller . remember ( filterManager . get ( "sobel" ) ) ; Controller . remember ( filterManager . get ( "canny" ) ) ; Controller . remember ( filterManager . get ( "gaussian" ) ) ; Controller . remember ( filterManager . get ( "haar_face" ) ) ; CFolder . custom = Controller . addFolder ( "custom" ) ;
CFolder . resolution = CFolder . custom . addFolder ( "Image Resolution" ) ; CFolder . resolution . add ( filterManager . get ( "resolution" ) , "width" , 0 , 2 ) . step ( . 1 ) ; CFolder . resolution . add ( filterManager . get ( "resolution" ) , "height" , 0 , 2 ) . step ( . 1 ) ; CFolder . basic = CFolder . custom . addFolder ( "Basic Image Processing" ) ; CFolder . basic . add ( filterManager . get ( "contrast" ) , "contrast" , 0 , 100 ) ; CFolder . basic . add ( filterManager . get ( "grayscale" ) , "grayscale" ) ; CFolder . tracking = Controller . addFolder ( "Tracking.js" ) ; CFolder . face _tracking = CFolder . tracking . addFolder ( "Face tracking" ) ;
CFolder . face _tracking . add ( filterManager . get ( "face_tracking" ) , "apply" ) ; CFolder . face _tracking . add ( filterManager . get ( "face_tracking" ) , "initial_scale" , 1 , 10 ) . step ( . 5 ) ; CFolder . face _tracking . add ( filterManager . get ( "face_tracking" ) , "step_size" , 1 , 5 ) . step ( . 5 ) ; CFolder . face _tracking . add ( filterManager . get ( "face_tracking" ) , "edges_density" , . 1 , . 5 ) . step ( . 01 ) ; CFolder . jsfeat = Controller . addFolder ( "jsfeat" ) ; CFolder . haar _face = CFolder . jsfeat . addFolder ( "Haar Face Detection" ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) ,
"apply" ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) , "min_scale" , 1 , 4 ) . step ( . 1 ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) , "scale_factor" , 1.1 , 2 ) . step ( . 025 ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) , "equalize_histogram" ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) , "use_canny" ) ; CFolder . haar _face . add ( filterManager . get ( "haar_face" ) , "edges_density" , . 01 , 1 ) . step ( . 005 ) ; CFolder . gaussian = CFolder . jsfeat . addFolder ( "Gaussian Blur" ) ; CFolder . gaussian . add ( filterManager . get ( "gaussian" ) ,
"active" ) ; CFolder . gaussian . add ( filterManager . get ( "gaussian" ) , "sigma" , 0 , 10 ) . step ( . 5 ) ; CFolder . gaussian . add ( filterManager . get ( "gaussian" ) , "radius" , 1 , 11 ) . step ( 1 ) ; CFolder . sobel = CFolder . jsfeat . addFolder ( "Sobel Filter" ) ; CFolder . sobel . add ( filterManager . get ( "sobel" ) , "sobelActive" ) ; CFolder . canny = CFolder . jsfeat . addFolder ( "Canny Filter" ) ; CFolder . canny . add ( filterManager . get ( "canny" ) , "active" ) ; CFolder . canny . add ( filterManager . get ( "canny" ) , "radius" , 0 , 4 ) . step ( 1 ) ; CFolder . canny . add ( filterManager . get ( "canny" ) , "low_threshold" ,
1 , 127 ) . step ( 1 ) ; CFolder . canny . add ( filterManager . get ( "canny" ) , "high_threshold" , 1 , 127 ) . step ( 1 ) ; CFolder . process = Controller . addFolder ( "Process" ) ; CFolder . process . add ( { render : process } , "render" ) ; Controller . _ _save _row . children [ 2 ] . addEventListener ( "click" , function ( ) { Controller . save ( ) ; try { var a = JSON . stringify ( Controller . getSaveObject ( ) ) ; ControllerRememberer . store ( a , function ( ) { log ( "dat.GUI preset stored." , "[PermanentStorage]" ) ; return ! 0 } ) } catch ( c ) { log ( "Corrupted data." , "[PermanentStorage]" ) } } , ! 1 ) ; iL = new ImageLoader ( DOM . imageLoader ,
init , process ) ; return ! 0 } ) ;