@ Override protected ImageWritable doTransform ( ImageWritable image , Random random ) { if ( image == null ) { return null ; } Mat mat = converter . convert ( image . getFrame ( ) ) ; Mat box = new Mat ( height , width , mat . type ( ) ) ; box . put ( borderValue ) ; x = ( mat . cols ( ) - width ) / 2 ; y = ( mat . rows ( ) - height ) / 2 ; int w = Math . min ( mat . cols ( ) , width ) ; int h = Math . min ( mat . rows ( ) , height ) ; Rect matRect = new Rect ( x , y , w , h ) ; Rect boxRect = new Rect ( x , y , w , h ) ; if ( x <= 0 ) { matRect . x ( 0 ) ; boxRect . x ( - x ) ; } else { matRect . x ( x ) ; boxRect . x ( 0 ) ; } if ( y <= 0 ) { matRect . y ( 0 ) ; boxRect . y ( - y ) ; } else { matRect . y ( y ) ; boxRect . y ( 0 ) ; } mat . apply ( matRect ) . copyTo ( box . apply ( boxRect ) ) ; return new ImageWritable ( converter . convert ( box ) ) ; }
Takes an image and returns a boxed version of the image .