public ImageWritable asWritable ( File f ) throws IOException { try ( BufferedInputStream bis = new BufferedInputStream ( new FileInputStream ( f ) ) ) { Mat mat = streamToMat ( bis ) ; Mat image = imdecode ( mat , IMREAD_ANYDEPTH | IMREAD_ANYCOLOR ) ; if ( image == null || image . empty ( ) ) { PIX pix = pixReadMem ( mat . data ( ) , mat . cols ( ) ) ; if ( pix == null ) { throw new IOException ( "Could not decode image from input stream" ) ; } image = convert ( pix ) ; pixDestroy ( pix ) ; } ImageWritable writable = new ImageWritable ( converter . convert ( image ) ) ; return writable ; } }
Convert a file to a INDArray