add a wrapper for getAvailableTargets#16273
Merged
alalek merged 2 commits intoopencv:3.4from Jan 17, 2020
Merged
Conversation
Member
|
Thanks! |
Contributor
Author
|
done |
Member
|
Could you please add simple bindings tests?
Check should be simple enough ( Thank you! |
Contributor
Author
|
@alalek something like this? |
Member
|
@JulienMaille Yes |
Contributor
Author
|
I tried my best, but I'm gonna need help with the java test |
27582c4 to
651f17b
Compare
Contributor
Author
|
@alalek Python test is ok but this is the error I get for the java one: I probably has to do with the fact it expects an enum Backend and receives an int |
Contributor
Author
|
@dkurt can the issue with java be solved without changing the signature to take an int instead of an enum? |
Member
|
@JulienMaille, I will try to check it. |
Member
|
@JulienMaille, may I ask you to try the following changes? diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp
index a2030ad..4699dac 100644
--- a/modules/dnn/include/opencv2/dnn/dnn.hpp
+++ b/modules/dnn/include/opencv2/dnn/dnn.hpp
@@ -97,7 +97,7 @@ CV__DNN_INLINE_NS_BEGIN
};
CV_EXPORTS std::vector< std::pair<Backend, Target> > getAvailableBackends();
- CV_EXPORTS_W std::vector<Target> getAvailableTargets(Backend be);
+ CV_EXPORTS_W std::vector<Target> getAvailableTargets(dnn::Backend be);
/** @brief This class provides all data needed to initialize layer.
*
diff --git a/modules/dnn/misc/java/gen_dict.json b/modules/dnn/misc/java/gen_dict.json
index c0e0a1b..5a397ea 100644
--- a/modules/dnn/misc/java/gen_dict.json
+++ b/modules/dnn/misc/java/gen_dict.json
@@ -36,6 +36,14 @@
"v_type": "vector_Layer",
"j_import": "org.opencv.dnn.Layer"
},
+ "vector_Target": {
+ "j_type": "List<Integer>",
+ "jn_type": "List<Integer>",
+ "jni_type": "jobject",
+ "jni_var": "std::vector< cv::dnn::Target > %(n)s",
+ "suffix": "Ljava_util_List",
+ "v_type": "vector_Target"
+ },
"LayerId": {
"j_type": "DictValue",
"jn_type": "long",
diff --git a/modules/dnn/misc/java/src/cpp/dnn_converters.cpp b/modules/dnn/misc/java/src/cpp/dnn_converters.cpp
index 1d259ae..95184c0 100644
--- a/modules/dnn/misc/java/src/cpp/dnn_converters.cpp
+++ b/modules/dnn/misc/java/src/cpp/dnn_converters.cpp
@@ -60,6 +60,25 @@ jobject vector_Ptr_Layer_to_List(JNIEnv* env, std::vector<cv::Ptr<cv::dnn::Layer
return result;
}
+jobject vector_Target_to_List(JNIEnv* env, std::vector<cv::dnn::Target>& vs)
+{
+ static jclass juArrayList = ARRAYLIST(env);
+ static jmethodID m_create = CONSTRUCTOR(env, juArrayList);
+ jmethodID m_add = LIST_ADD(env, juArrayList);
+
+ static jclass jInteger = env->FindClass("java/lang/Integer");
+ static jmethodID m_create_Integer = env->GetMethodID(jInteger, "<init>", "(I)V");
+
+ jobject result = env->NewObject(juArrayList, m_create, vs.size());
+ for (size_t i = 0; i < vs.size(); ++i)
+ {
+ jobject element = env->NewObject(jInteger, m_create_Integer, vs[i]);
+ env->CallBooleanMethod(result, m_add, element);
+ env->DeleteLocalRef(element);
+ }
+ return result;
+}
+
std::vector<cv::Ptr<cv::dnn::Layer> > List_to_vector_Ptr_Layer(JNIEnv* env, jobject list)
{
static jclass juArrayList = ARRAYLIST(env);
diff --git a/modules/dnn/misc/java/src/cpp/dnn_converters.hpp b/modules/dnn/misc/java/src/cpp/dnn_converters.hpp
index 6a72701..e1f63e0 100644
--- a/modules/dnn/misc/java/src/cpp/dnn_converters.hpp
+++ b/modules/dnn/misc/java/src/cpp/dnn_converters.hpp
@@ -28,5 +28,6 @@ jobject vector_Ptr_Layer_to_List(JNIEnv* env, std::vector<cv::Ptr<cv::dnn::Layer
std::vector<cv::Ptr<cv::dnn::Layer> > List_to_vector_Ptr_Layer(JNIEnv* env, jobject list);
+jobject vector_Target_to_List(JNIEnv* env, std::vector<cv::dnn::Target>& vs);
#endif /* DNN_CONVERTERS_HPP */ |
651f17b to
6f1dd88
Compare
Contributor
Author
|
@dkurt done |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
as requested by @dkurt here: #16184 (comment)