I would like to pass an array of arrays calculated from a native method in a Java class. To do this I thought to call the method setTarghet from native code to set each vector field. I think it's a good idea. this is a java class:
public class struttura {
private int _facetCount;
public Mat [] VectorTarget;
public struttura(int facetCount)
{
_facetCount = facetCount;
VectorTarget = new Mat[facetCount];
}
public int getFacetCount()
{
return _facetCount;
}
public void setTarget (int index,Mat value)
{
VectorTarget[index]=value;
}
}
this is native code
JNIEXPORT void JNICALL Java_com_example_nonfreejnidemo_NonfreeJNILib_extractorSuTarget(JNIEnv * env, jobject obj, jint nT )
{
.....
Mat object[50];
// read 50 image and put them in object[i]
for (unsigned int i = 0;i < 50 ;i++) {
object[i] = imread( files[i], CV_LOAD_IMAGE_GRAYSCALE );
}
//Detect the keypoints using SURF Detector
int minHessian = 500;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> kp_object[nT];
for (unsigned int i = 0;i < nT; i++)
{
detector.detect( object[i], kp_object[i] );
}
//Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat des_object[nT];
for (unsigned int i = 0;i < nT; i++)
{
extractor.compute( object[i], kp_object[i], des_object[i] );
}
//-----------------------------------------------------------------------------------------------
// now begin my problem
// i want to call method setTarget from java code to map des_object on VectorTarget
// and use it on java code.
// i try something like this but i have some errors.
// i now that it is not correct, i do not know how write it.
for (int index=0; index <50; index++)
{
jlong y = (jlong)des_object[index] ;
jclass cls = env->GetObjectClass(obj);
jmethodID methodId = env->GetMethodID( cls, "setTarget", "(IJ)V");
env->CallVoidMethod(obj, methodId,index,y );
}
//-----------------------------------------------------------------------------------------------
i want to call method setTarget from java code to map des_object on VectorTarget and use it on java code. i try something like this but i have some errors. i know that it is not correct, i do not know how write it please help me.