I am developing application for recognising Sudoku from paper and showing it on the screen. Since I am using OpenCV, I've tried to convert Mat object to PNG image. I tried to use this code:
private static void Mat2BufferedImage(Mat m, String s){
int type = BufferedImage.TYPE_BYTE_GRAY;
if ( m.channels() > 1 ) {
type = BufferedImage.TYPE_3BYTE_BGR;
}
int bufferSize = m.channels()*m.cols()*m.rows();
byte [] b = new byte[bufferSize];
m.get(0,0,b);
BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.arraycopy(b, 0, targetPixels, 0, b.length);
File f = new File("resources/img-" + s + ".png");
try {
ImageIO.write(image, "PNG", f);
} catch (IOException e) {
e.printStackTrace();
}
}
, but I am unable since BufferedImage is not supported anymore. Is there any other way to do this? I am not so good with OpenCV.