From 790ff8f42a726b295d55836db368cdcd5eae1270 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 3 Aug 2011 15:23:33 +0000 Subject: [PATCH] Java API: minEnclosingCircle() fixed (float& -> float[]) Testing: 1130/0/584 --- .../org/opencv/test/imgproc/imgprocTest.java | 4 +-- modules/java/gen_java.py | 31 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java b/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java index c7bc76dd7..61a3f9d14 100644 --- a/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java +++ b/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java @@ -1414,14 +1414,14 @@ public class imgprocTest extends OpenCVTestCase { points.add(new Point(0, 1)); Point actualCenter = new Point(); - float radius = 347.0f; // FIXME: Unexpected radius is returned i.e 0 + float[] radius = new float[]{347.0f}; Imgproc.minEnclosingCircle(points, actualCenter, radius); Point truthCenter = new Point(0, 0); assertEquals(truthCenter, actualCenter); float truthRadius = 1.0f; - assertEquals(truthRadius, radius, weakEPS); + assertEquals(truthRadius, radius[0], weakEPS); } public void testMomentsMat() { diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index f347e275e..665adff0c 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -876,7 +876,7 @@ extern "C" { args = fi.args[:] # copy suffix_counter = int( self.classes[fi.classname or self.Module].methods_suffixes.get(fi.jname, -1) ) while True: - suffix_counter = suffix_counter + 1 + suffix_counter += 1 self.classes[fi.classname or self.Module].methods_suffixes[fi.jname] = suffix_counter # java native method args jn_args = [] @@ -923,17 +923,20 @@ extern "C" { jn_args.append ( ArgInfo([ "double[]", "%s_out" % a.name, "", [], "" ]) ) jni_args.append ( ArgInfo([ "double[]", "%s_out" % a.name, "", [], "" ]) ) j_prologue.append( "double[] %s_out = new double[%i];" % (a.name, len(fields)) ) - set_vals = [] - i = 0 - for f in fields: - set_vals.append( "%(n)s%(f)s = %(t)s%(n)s_out[%(i)i]" % - {"n" : a.name, "t": ("("+type_dict[f[0]]["j_type"]+")", "")[f[0]=="double"], "f" : f[1], "i" : i} - ) - i += 1 - j_epilogue.append("; ".join(set_vals) + "; ") c_epilogue.append( \ "jdouble tmp_%(n)s[%(cnt)i] = {%(args)s}; env->SetDoubleArrayRegion(%(n)s_out, 0, %(cnt)i, tmp_%(n)s);" % { "n" : a.name, "cnt" : len(fields), "args" : ", ".join([a.name + f[1] for f in fields]) } ) + if a.ctype in ('bool', 'int', 'long', 'float', 'double'): + j_epilogue.append('if(%(n)s!=null) %(n)s[0] = (%(t)s)%(n)s_out[0];' % {'n':a.name,'t':a.ctype}) + else: + set_vals = [] + i = 0 + for f in fields: + set_vals.append( "%(n)s%(f)s = %(t)s%(n)s_out[%(i)i]" % + {"n" : a.name, "t": ("("+type_dict[f[0]]["j_type"]+")", "")[f[0]=="double"], "f" : f[1], "i" : i} + ) + i += 1 + j_epilogue.append( "if("+a.name+"!=null){ " + "; ".join(set_vals) + "; } ") # java part: @@ -990,6 +993,13 @@ extern "C" { if fi.classname: static = fi.static + j_args = [] + for a in args: + jt = type_dict[a.ctype]["j_type"] + if a.out and a.ctype in ('bool', 'int', 'long', 'float', 'double'): + jt += '[]' + j_args.append( jt + ' ' + a.name ) + j_code.write( Template(\ """ public $static $j_type $j_name($j_args) { @@ -1009,12 +1019,13 @@ extern "C" { static=static, \ j_type=type_dict[fi.ctype]["j_type"], \ j_name=fi.jname, \ - j_args=", ".join(["%s %s" % (type_dict[a.ctype]["j_type"], a.name) for a in args]), \ + j_args=", ".join(j_args), \ jn_name=fi.jname + '_' + str(suffix_counter), \ jn_args_call=", ".join( [a.name for a in jn_args] ),\ ) ) + # cpp part: # jni_func(..) { _retval_ = cv_func(..); return _retval_; } ret = "return _retval_;"