Commit 4c2100e0 authored by Dmitry Kurtaev's avatar Dmitry Kurtaev Committed by Alexander Alekhin

Merge pull request #14266 from dkurt:fix_qrcode_decode_java

* Fix decode and detectAndDecode Java wrappers for QRCodeDetector

* revert changes in objdetect

* java: fix wrapping of std::string type
parent 473941c3
......@@ -64,7 +64,16 @@ type_dict = {
"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" },
"int64" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" },
"double[]": { "j_type" : "double[]", "jn_type" : "double[]", "jni_type" : "jdoubleArray", "suffix" : "_3D" }
"double[]": { "j_type" : "double[]", "jn_type" : "double[]", "jni_type" : "jdoubleArray", "suffix" : "_3D" },
'string' : { # std::string, see "String" in modules/core/misc/java/gen_dict.json
'j_type': 'String',
'jn_type': 'String',
'jni_name': 'n_%(n)s',
'jni_type': 'jstring',
'jni_var': 'const char* utf_%(n)s = env->GetStringUTFChars(%(n)s, 0); std::string n_%(n)s( utf_%(n)s ? utf_%(n)s : "" ); env->ReleaseStringUTFChars(%(n)s, utf_%(n)s)',
'suffix': 'Ljava_lang_String_2',
'j_import': 'java.lang.String'
},
}
# Defines a rule to add extra prefixes for names from specific namespaces.
......@@ -831,7 +840,7 @@ class JavaWrapperGenerator(object):
ret = "return (jlong) _retval_;"
else: # returned as jobject
ret = "return _retval_;"
elif fi.ctype == "String":
elif fi.ctype in ['String', 'string']:
ret = "return env->NewStringUTF(_retval_.c_str());"
default = 'return env->NewStringUTF("");'
elif self.isWrapped(fi.ctype): # wrapped class:
......@@ -858,6 +867,8 @@ class JavaWrapperGenerator(object):
retval = ""
elif fi.ctype == "String":
retval = "cv::" + retval
elif fi.ctype == "string":
retval = "std::" + retval
elif "v_type" in type_dict[fi.ctype]: # vector is returned
retval = type_dict[fi.ctype]['jni_var'] % {"n" : '_ret_val_vector_'} + " = "
if type_dict[fi.ctype]["v_type"] in ("Mat", "vector_Mat"):
......
package org.opencv.test.objdetect;
import org.opencv.core.Mat;
import org.opencv.objdetect.QRCodeDetector;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.objdetect.Objdetect;
import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
public class QRCodeDetectorTest extends OpenCVTestCase {
private final static String ENV_OPENCV_TEST_DATA_PATH = "OPENCV_TEST_DATA_PATH";
private String testDataPath;
@Override
protected void setUp() throws Exception {
super.setUp();
testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
if (testDataPath == null)
throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
}
public void testDetectAndDecode() {
Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/link_ocv.jpg");
QRCodeDetector detector = new QRCodeDetector();
String output = detector.detectAndDecode(img);
assertEquals(output, "https://opencv.org/");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment