android: use .getRowStride() in JavaCamera2View

This commit is contained in:
Alexander Alekhin
2019-10-27 11:14:17 +00:00
parent d8ab83600b
commit 80c4cedd25
4 changed files with 90 additions and 14 deletions
@@ -41,6 +41,15 @@ public class Mat {
nativeObj = n_Mat(rows, cols, type, data);
}
//
// C++: Mat::Mat(int rows, int cols, int type, void* data, size_t step)
//
// javadoc: Mat::Mat(rows, cols, type, data, step)
public Mat(int rows, int cols, int type, ByteBuffer data, long step) {
nativeObj = n_Mat(rows, cols, type, data, step);
}
//
// C++: Mat::Mat(Size size, int type)
//
@@ -1136,6 +1145,9 @@ public class Mat {
// C++: Mat::Mat(int rows, int cols, int type, void* data)
private static native long n_Mat(int rows, int cols, int type, ByteBuffer data);
// C++: Mat::Mat(int rows, int cols, int type, void* data, size_t step)
private static native long n_Mat(int rows, int cols, int type, ByteBuffer data, long step);
// C++: Mat::Mat(Size size, int type)
private static native long n_Mat(double size_width, double size_height, int type);
+18
View File
@@ -1246,4 +1246,22 @@ public class MatTest extends OpenCVTestCase {
assertEquals(1, bbuf.get(4095));
}
public void testMatFromByteBufferWithStep() {
ByteBuffer bbuf = ByteBuffer.allocateDirect(80*64);
bbuf.putInt(0x01010101);
bbuf.putInt(64, 0x02020202);
bbuf.putInt(80, 0x03030303);
Mat m = new Mat(64, 64, CvType.CV_8UC1, bbuf, 80);
assertEquals(8, Core.countNonZero(m));
Core.add(m, new Scalar(5), m);
assertEquals(4096, Core.countNonZero(m));
m.release();
assertEquals(6, bbuf.get(0));
assertEquals(5, bbuf.get(63));
assertEquals(2, bbuf.get(64));
assertEquals(0, bbuf.get(79));
assertEquals(8, bbuf.get(80));
assertEquals(5, bbuf.get(63*80 + 63));
}
}