Ask Your Question

Revision history [back]

Mat data type is not compatible: 16

This loads just fine:

    private Mat m = Imgcodecs.imread("C:/Users/Link/workspace/G3DExperiment/src/imgres/stone.png");

But for some reason I can't load it into an array:

public void draw(Mat mat, int x, int y) {
    int rows = mat.rows(), cols = mat.cols(), type = CvType.channels(mat.type());
    int[] bgr = new int[rows*cols*type];
    mat.get(0, 0, bgr);
    canvas.setRGB(x, y, cols, rows, bgr, 0, width);
}

The full stacktrace reads:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Mat data type is not compatible: 16
at org.opencv.core.Mat.get(Mat.java:2599)
at genesis.g2D.MatrixCanvas.draw(MatrixCanvas.java:158)
at g.Main.<init>(Main.java:49)
at g.Main.<init>(Main.java:42)
at g.Main$1.run(Main.java:37)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Mat data type is not compatible: 16

This loads just fine:

    private Mat m = Imgcodecs.imread("C:/Users/Link/workspace/G3DExperiment/src/imgres/stone.png");

But for some reason I can't load it into an array:

public void draw(Mat mat, int x, int y) {
    int rows = mat.rows(), cols = mat.cols(), type = CvType.channels(mat.type());
    int[] bgr = new int[rows*cols*type];
    mat.get(0, 0, bgr);
    canvas.setRGB(x, y, cols, rows, bgr, 0, width);
}

canvas is a BufferedImage of type TYPE_3BYTE_BGR and this method MatrixCanvas#draw(Mat, int, int) is used to draw a Mat directly onto the screen by covering the screen in a BufferedImage and setting the pixels on the image.

The full stacktrace reads:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Mat data type is not compatible: 16
at org.opencv.core.Mat.get(Mat.java:2599)
at genesis.g2D.MatrixCanvas.draw(MatrixCanvas.java:158)
at g.Main.<init>(Main.java:49)
at g.Main.<init>(Main.java:42)
at g.Main$1.run(Main.java:37)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Mat data type is not compatible: 16Image loads; Cannot put into array

This loads just fine:

    private Mat m = Imgcodecs.imread("C:/Users/Link/workspace/G3DExperiment/src/imgres/stone.png");

But for some reason I can't load it into an array:

public void draw(Mat mat, int x, int y) {
    int rows = mat.rows(), cols = mat.cols(), type = CvType.channels(mat.type());
    int[] bgr = new int[rows*cols*type];
    mat.get(0, 0, bgr);
    canvas.setRGB(x, y, cols, rows, bgr, 0, width);
}

canvas is a BufferedImage of type TYPE_3BYTE_BGR and this method MatrixCanvas#draw(Mat, int, int) is used to draw a Mat directly onto the screen by covering the screen in a BufferedImage and setting the pixels on the image.

The full stacktrace reads:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Mat data type is not compatible: 16
at org.opencv.core.Mat.get(Mat.java:2599)
at genesis.g2D.MatrixCanvas.draw(MatrixCanvas.java:158)
at g.Main.<init>(Main.java:49)
at g.Main.<init>(Main.java:42)
at g.Main$1.run(Main.java:37)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)