我试图将缓冲的图像转换为Matrix,但它会抛出一个我以前从未见过的UnsupportedOperationException
public static Mat readMatImage(String path) {
Mat mat = null;
BufferedImage image;
try {
image = ImageIO.read(new FileInputStream(path));
mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);
byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.out.println(data[data.length - 1]);
mat.put(0, 0, data);
} catch (IOException e) {
e.printStackTrace();
}
return mat;
}
Exception in thread "main" java.lang.UnsupportedOperationException: Provided data element number (4000000) should be multiple of the Mat channels count (3)
答案 0 :(得分:0)
我认为您应该考虑您的读取图像类型,因为您的图像必须是单通道和8位才能将其转换为mat元素。如果您的图像是RGB,请尝试将其转换为二进制图像。