前言
opencv中字节与mat互转,直接上代码
字节转mat
//以上省略
//dataImg为要转换的图片字节数组 byte[]
MatOfByte matIntOfByte = new MatOfByte(dataImg);
Mat imgTemMat = Imgcodecs.imdecode(matIntOfByte, Imgcodecs.IMREAD_UNCHANGED);
mat转字节
//mat为你要转换的原始mat
MatOfByte matOfByte = new MatOfByte();
Imgcodecs.imencode(".jpg",mat,matOfByte);
byte[] bytes = matOfByte.toArray();