From ea735a04750b8042e1dcda7e91c24b7554e83000 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 25 Apr 2012 09:00:50 +0000 Subject: [PATCH] Java API: fixing Mat::put() for non-continuous Mat-s, adding/improving tests --- .../src/org/opencv/test/core/MatTest.java | 223 +++++++++++++++++---- .../src/org/opencv/test/imgproc/ImgprocTest.java | 39 +++- modules/java/src/cpp/Mat.cpp | 34 +++- 3 files changed, 242 insertions(+), 54 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/core/MatTest.java b/modules/java/android_test/src/org/opencv/test/core/MatTest.java index 03d8dcc..e6e065c 100644 --- a/modules/java/android_test/src/org/opencv/test/core/MatTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/MatTest.java @@ -272,23 +272,72 @@ public class MatTest extends OpenCVTestCase { assertEquals(5, Core.countNonZero(eye)); } + + public Mat getTestMat(int size, int type) { + Mat m = new Mat(size, size, type); + final int ch = CvType.channels(type); + double buff[] = new double[size*size * ch]; + for(int i=0; i images = Arrays.asList(gray255, gray128); MatOfInt channels = new MatOfInt(0, 1); MatOfInt histSize = new MatOfInt(10, 10); @@ -292,6 +292,43 @@ public class ImgprocTest extends OpenCVTestCase { assertMatEqual(truth, hist, EPS); } + public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() { + List images = Arrays.asList(rgbLena); + + Mat hist3D = new Mat(); + List histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} ); + + MatOfInt histSize = new MatOfInt(10); + MatOfFloat ranges = new MatOfFloat(0f, 256f); + + for(int i=0; i images = Arrays.asList(gray255, gray128); MatOfInt channels = new MatOfInt(0, 1); diff --git a/modules/java/src/cpp/Mat.cpp b/modules/java/src/cpp/Mat.cpp index 182a70d..fc748f2 100644 --- a/modules/java/src/cpp/Mat.cpp +++ b/modules/java/src/cpp/Mat.cpp @@ -2,11 +2,12 @@ #include "converters.h" -#ifdef DEBUG #include -#define MODULE_LOG_TAG "OpenCV.core.Mat" -#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__)) -#else //DEBUG +#define LOG_TAG "org.opencv.core.Mat" +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) +#ifdef DEBUG +#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) +#else //!DEBUG #define LOGD(...) #endif //DEBUG @@ -1979,7 +1980,7 @@ template static int mat_put(cv::Mat* m, int row, int col, int count, if(! buff) return 0; count *= sizeof(T); - int rest = ((m->rows - row) * m->cols - col) * m->channels() * sizeof(T); + int rest = ((m->rows - row) * m->cols - col) * m->elemSize(); if(count>rest) count = rest; int res = count; @@ -1988,14 +1989,14 @@ template static int mat_put(cv::Mat* m, int row, int col, int count, memcpy(m->ptr(row, col), buff, count); } else { // row by row - int num = (m->cols - col - 1) * m->channels() * sizeof(T); // 1st partial row + int num = (m->cols - col) * m->elemSize(); // 1st partial row if(countptr(row++, col); while(count>0){ memcpy(data, buff, num); count -= num; buff += num; - num = m->cols * m->channels() * sizeof(T); + num = m->cols * m->elemSize(); if(countptr(row++, 0); } @@ -2197,8 +2198,23 @@ JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump { cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL std::stringstream s; - s << *me; - return env->NewStringUTF(s.str().c_str()); + try { + LOGD("Mat::nDump()"); + + s << *me; + return env->NewStringUTF(s.str().c_str()); + } catch(cv::Exception e) { + LOGE("Mat::nDump() catched cv::Exception: %s", e.what()); + jclass je = env->FindClass("org/opencv/core/CvException"); + if(!je) je = env->FindClass("java/lang/Exception"); + env->ThrowNew(je, e.what()); + return env->NewStringUTF("ERROR"); + } catch (...) { + LOGE("Mat::nDump() catched unknown exception (...)"); + jclass je = env->FindClass("java/lang/Exception"); + env->ThrowNew(je, "Unknown exception in JNI code {Mat::nDump()}"); + return env->NewStringUTF("ERROR"); + } } -- 2.7.4