mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Merge pull request #12938 from dkurt:java_ndim_mat
This commit is contained in:
commit
76b6f6b017
@ -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());
|
||||
|
@ -528,7 +528,30 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// int Mat::size(int i)
|
||||
//
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1size_1i__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint i);
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1size_1i__JI
|
||||
(JNIEnv* env, jclass, jlong self, jint i)
|
||||
{
|
||||
static const char method_name[] = "Mat::n_1size_1i__JI()";
|
||||
try {
|
||||
LOGD("%s", method_name);
|
||||
Mat* me = (Mat*) self; //TODO: check for NULL
|
||||
int _retval_ = me->size[i];
|
||||
return _retval_;
|
||||
} catch(const std::exception &e) {
|
||||
throwJavaException(env, &e, method_name);
|
||||
} catch (...) {
|
||||
throwJavaException(env, 0, method_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta = 0)
|
||||
@ -1307,7 +1330,31 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Mat Mat::reshape(int cn, int[] newshape)
|
||||
//
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape_11
|
||||
(JNIEnv* env, jclass, jlong self, jint cn, jint newndims, jintArray newshape);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape_11
|
||||
(JNIEnv* env, jclass, jlong self, jint cn, jint newndims, jintArray newshape)
|
||||
{
|
||||
static const char method_name[] = "Mat::n_1reshape_11";
|
||||
try {
|
||||
LOGD("%s", method_name);
|
||||
Mat* me = (Mat*) self; //TODO: check for NULL
|
||||
int* newsz = (int*)env->GetPrimitiveArrayCritical(newshape, 0);
|
||||
Mat _retval_ = me->reshape( cn, newndims, newsz );
|
||||
return (jlong) new Mat(_retval_);
|
||||
} catch(const std::exception &e) {
|
||||
throwJavaException(env, &e, method_name);
|
||||
} catch (...) {
|
||||
throwJavaException(env, 0, method_name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Mat Mat::row(int y)
|
||||
|
Loading…
Reference in New Issue
Block a user