/** * Returns {@code asMatrix(image, false)}. */ public INDArray asMatrix(BufferedImage image) throws IOException { return asMatrix(image, false); }
@Override public INDArray asMatrix(Object image) throws IOException { return image instanceof BufferedImage ? asMatrix((BufferedImage) image) : null; }
/** * Returns {@code asMatrix(image, false).ravel()}. */ public INDArray asRowVector(BufferedImage image) throws IOException { return asMatrix(image, false).ravel(); }
/** * Returns {@code asMatrix(image, flipChannels).ravel()}. */ public INDArray asRowVector(BufferedImage image, boolean flipChannels) throws IOException { return asMatrix(image, flipChannels).ravel(); }
/** * Loads a {@link INDArray} from a {@link BufferedImage}. * * @param image as a BufferedImage * @param flipChannels to have a format like TYPE_INT_RGB (ARGB) output as BGRA, etc * @return the loaded matrix * @throws IOException */ public INDArray asMatrix(BufferedImage image, boolean flipChannels) throws IOException { if (converter == null) { converter = new OpenCVFrameConverter.ToMat(); } return asMatrix(converter.convert(converter2.getFrame(image, 1.0, flipChannels))); }
/** * Calls {@link AndroidNativeImageLoader#asMatrix(android.graphics.Bitmap)} or * {@link Java2DNativeImageLoader#asMatrix(java.awt.image.BufferedImage)}. * @param image as a {@link android.graphics.Bitmap} or {@link java.awt.image.BufferedImage} * @return the matrix or null for unsupported object classes * @throws IOException */ public INDArray asMatrix(Object image) throws IOException { INDArray array = null; if (array == null) { try { array = new AndroidNativeImageLoader(this).asMatrix(image); } catch (NoClassDefFoundError e) { // ignore } } if (array == null) { try { array = new Java2DNativeImageLoader(this).asMatrix(image); } catch (NoClassDefFoundError e) { // ignore } } return array; }