byte[] 转换为Mat
第一步:先定义一个自己要的Mat
Mat image1 = new Mat(240,320, CvType.CV_8UC1);
第二步:将你的byte[] grayData 放进去
image1.put(0,0,grayData);
好了,你的Mat生成啦
参考api代码(\openCVLibrary320\src\main\java\org\opencv\imgproc)中方法
public static Mat vector_uchar_to_Mat(List<Byte> bs) {
Mat res;
int count = (bs != null) ? () : 0;
if (count > 0) {
res = new Mat(count, 1, CvType.CV_8UC1);
byte[] buff = new byte[count];
for (int i = 0; i < count; i++) {
byte b = (i);
buff[i] = b;
}
(0, 0, buff);
} else {
res = new Mat();
}
return res;
}
Mat 转 byte[]
Mat grayMatData = new Mat();
cvtColor(rgbData,grayMatData,COLOR_RGB2GRAY);
byte [] grayData = new byte[()*()];
grayMatData.get(0,0,grayData);