From 2b83d416b0ff23bcb8a907c9f8b316af1f8ff02f Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Fri, 1 Jul 2011 15:48:13 +0000 Subject: [PATCH] #863: default Mat() c-tor, minor improvements --- modules/java/gen_java.py | 12 +++++++++--- modules/java/src/cpp/Mat.cpp | 22 +++++++++++++++++++++- modules/java/src/java/Mat.java | 11 +++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index ea0c8e2d05..efb5d64492 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -20,10 +20,10 @@ type_dict = { "double" : { "j_type" : "double", "jn_type" : "double", "jni_type" : "jdouble", "suffix" : "D" }, "size_t" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" }, "__int64" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" }, - #"+Mat+" : { "j_type" : "Mat", "jn_type" : "long", "jn_name" : "%s.nativeObj", "jni_type" : "jlong", "suffix" : "J" }, # "complex" : { j_type : "?", jn_args : (("", ""),), jn_name : "", jni_var : "", jni_name : "", "suffix" : "?" }, "Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), - "jni_var" : "cv::Mat %(n)s(%(n)s_nativeObj ? *((cv::Mat*)%(n)s_nativeObj) : cv::Mat())", "jni_type" : "jlong", + "jni_var" : "cv::Mat& %(n)s = *((cv::Mat*)%(n)s_nativeObj); //cv::Mat& %(n)s = (%(n)s_nativeObj ? *((cv::Mat*)%(n)s_nativeObj) : cv::Mat())", + "jni_type" : "jlong", #"jni_name" : "*%(n)s", "suffix" : "J" }, "Point" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")), "jni_var" : "cv::Point %(n)s((int)%(n)s_x, (int)%(n)s_y)", @@ -166,7 +166,7 @@ class JavaWrapperGenerator(object): sys.exit(-1) type_dict[classinfo.name] = \ { "j_type" : classinfo.name, "jn_args" : (("__int64", ".nativeObj"),), - "jni_name" : "(*((cv::"+classinfo.name+"*)%s_nativeObj))", + "jni_name" : "(*((cv::"+classinfo.name+"*)%(n)s_nativeObj))", "suffix" : "J" } @@ -268,6 +268,11 @@ public class %(module)s { """// This file is auto-generated, please don't edit! #include +/* +#include +#define TEGRA_LOG_TAG "OpenCV_for_Android" +#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, TEGRA_LOG_TAG, __VA_ARGS__)) +*/ """ % {"module" : module}) self.cpp_code.write( "\n".join(['#include "opencv2/%s/%s"' % (module, os.path.basename(f)) \ @@ -459,6 +464,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname ($args) { $j2cv + //LOGD("$module :: $fname"); $ret( $cvname( $cvargs ) ); } diff --git a/modules/java/src/cpp/Mat.cpp b/modules/java/src/cpp/Mat.cpp index b39ca1e1b2..730a7a94a9 100644 --- a/modules/java/src/cpp/Mat.cpp +++ b/modules/java/src/cpp/Mat.cpp @@ -1,8 +1,21 @@ #include +/* +#include +#define TEGRA_LOG_TAG "MAT_CPP" +#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, TEGRA_LOG_TAG, __VA_ARGS__)) +*/ #ifdef __cplusplus extern "C" { #endif +/* + * Class: org_opencv_Mat + * Method: nCreateMat + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__ + (JNIEnv *, jclass); + /* * Class: org_opencv_Mat * Method: nCreateMat @@ -594,6 +607,12 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nInv return 0; //NYI } +JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__ + (JNIEnv* env, jclass cls) +{ + return (jlong) new cv::Mat(); +} + JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nEye (JNIEnv* env, jclass cls, jint _rows, jint _cols, jint _type) { @@ -603,7 +622,8 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nEye JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__III (JNIEnv* env, jclass cls, jint _rows, jint _cols, jint _type) { - return (jlong) new cv::Mat( _rows, _cols, _type ); + //LOGD("called with r=%d, c=%d", _rows, _cols); + return (jlong) new cv::Mat( _rows, _cols, _type );; } JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nCreateMat__IIIDDDD diff --git a/modules/java/src/java/Mat.java b/modules/java/src/java/Mat.java index 0b02858f64..bab9a10af7 100644 --- a/modules/java/src/java/Mat.java +++ b/modules/java/src/java/Mat.java @@ -1,5 +1,7 @@ package org.opencv; +//import android.util.Log; + public class Mat { public static class CvType { @@ -113,7 +115,7 @@ public class Mat { s = "CV_USRTYPE1"; } - return s + "(" + channels() + ")"; + return s + "C(" + channels() + ")"; } // hashCode() has to be overridden if equals() is @@ -135,6 +137,10 @@ public class Mat { this.nativeObj = nativeMat; } + public Mat() { + this( nCreateMat() ); + } + public Mat(int rows, int cols, CvType type) { this( nCreateMat(rows, cols, type.toInt()) ); } @@ -388,8 +394,9 @@ public class Mat { } // native stuff - static { System.loadLibrary("opencv_java"); } + static { System.loadLibrary("opencv_java"); ); } protected long nativeObj; + private static native long nCreateMat(); private static native long nCreateMat(int rows, int cols, int type); private static native long nCreateMat(int rows, int cols, int type, double v0, double v1, double v2, double v3); private static native void nDispose(long self);