Add methods to reshape Mat in Java by array of shapes and retreive sizes of each dimension.
This commit is contained in:
@@ -681,6 +681,18 @@ public class Mat {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: Mat Mat::reshape(int cn, int newndims, const int* newsz)
|
||||
//
|
||||
|
||||
// javadoc: Mat::reshape(cn, newshape)
|
||||
public Mat reshape(int cn, int[] newshape)
|
||||
{
|
||||
Mat retVal = new Mat(n_reshape_1(nativeObj, cn, newshape.length, newshape));
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: Mat Mat::row(int y)
|
||||
//
|
||||
@@ -794,6 +806,18 @@ public class Mat {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: int Mat::size(int i)
|
||||
//
|
||||
|
||||
// javadoc: Mat::size(int i)
|
||||
public int size(int i)
|
||||
{
|
||||
int retVal = n_size_i(nativeObj, i);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// C++: size_t Mat::step1(int i = 0)
|
||||
//
|
||||
@@ -1271,6 +1295,9 @@ public class Mat {
|
||||
|
||||
private static native long n_reshape(long nativeObj, int cn);
|
||||
|
||||
// C++: Mat Mat::reshape(int cn, int newndims, const int* newsz)
|
||||
private static native long n_reshape_1(long nativeObj, int cn, int newndims, int[] newsz);
|
||||
|
||||
// C++: Mat Mat::row(int y)
|
||||
private static native long n_row(long nativeObj, int y);
|
||||
|
||||
@@ -1294,6 +1321,9 @@ public class Mat {
|
||||
// C++: Size Mat::size()
|
||||
private static native double[] n_size(long nativeObj);
|
||||
|
||||
// C++: int Mat::size(int i)
|
||||
private static native int n_size_i(long nativeObj, int i);
|
||||
|
||||
// C++: size_t Mat::step1(int i = 0)
|
||||
private static native long n_step1(long nativeObj, int i);
|
||||
|
||||
|
||||
@@ -817,6 +817,19 @@ public class MatTest extends OpenCVTestCase {
|
||||
assertMatEqual(truth, dst);
|
||||
}
|
||||
|
||||
public void testReshapeIntIntArray() {
|
||||
Mat src = new Mat(6, 5, CvType.CV_8UC3, new Scalar(0));
|
||||
assertEquals(2, src.dims());
|
||||
assertEquals(src.rows(), src.size(0));
|
||||
assertEquals(src.cols(), src.size(1));
|
||||
|
||||
int[] newShape = {1, src.channels() * src.cols(), 1, src.rows()};
|
||||
dst = src.reshape(1, newShape);
|
||||
assertEquals(newShape.length, dst.dims());
|
||||
for (int i = 0; i < newShape.length; ++i)
|
||||
assertEquals(newShape[i], dst.size(i));
|
||||
}
|
||||
|
||||
public void testRow() {
|
||||
Mat row = gray0.row(0);
|
||||
assertEquals(1, row.rows());
|
||||
|
||||
Reference in New Issue
Block a user