public void setTemplate ( GrayF32 image , List < Point2D_F64 > sides ) { if ( sides . size ( ) != 4 ) throw new IllegalArgumentException ( "Expected 4 sidesCollision" ) ; removePerspective . apply ( image , sides . get ( 0 ) , sides . get ( 1 ) , sides . get ( 2 ) , sides . get ( 3 ) ) ; templateOriginal . setTo ( removePerspective . getOutput ( ) ) ; // blur the image a bit so it doesn't have to be a perfect match GrayF32 blurred = new GrayF32 ( LENGTH , LENGTH ) ; BlurImageOps . gaussian ( templateOriginal , blurred , - 1 , 2 , null ) ; // place greater importance on pixels which are around edges GrayF32 derivX = new GrayF32 ( LENGTH , LENGTH ) ; GrayF32 derivY = new GrayF32 ( LENGTH , LENGTH ) ; GImageDerivativeOps . gradient ( DerivativeType . SOBEL , blurred , derivX , derivY , BorderType . EXTENDED ) ; GGradientToEdgeFeatures . intensityE ( derivX , derivY , weights ) ; float max = ImageStatistics . max ( weights ) ; PixelMath . divide ( weights , max , weights ) ; totalWeight = ImageStatistics . sum ( weights ) ; // compute a normalized template for later use. Divide by the mean to add some lighting invariance template . setTo ( removePerspective . getOutput ( ) ) ; float mean = ( float ) ImageStatistics . mean ( template ) ; PixelMath . divide ( template , mean , template ) ; }
Creates a template of the fiducial and this is then used to determine how blurred the image is