入门从本地code关键点回 [英] Getting keypoint back from native code

查看:166
本文介绍了入门从本地code关键点回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的OpenCV-SDK-机器人。 我想,我的原生code应该回到关键点向量。它正确使用code这样的..

I am using opencv-sdk-android. I want that my native code should return keypoint vector. Is it correct to use code like this..

矢量<关键点>关键点= FindFeatures(Gray1.getNativeObjAddr(),descriptor.getNativeObjAddr());

public native Vector<KeyPoint> FindFeatures(long matAddrGr1, long matAddrGr2);

我的natice code是

My natice code is

extern "C" {
JNIEXPORT Vector<KeyPoint> JNICALL Java_com_example_xyz_MainActivity_FindFeatures(JNIEnv*, jobject, jlong addrGray1, jlong addrdescrptor);

JNIEXPORT Vector<KeyPoint> JNICALL Java_com_example_xyz_MainActivity_FindFeatures(JNIEnv*, jobject, jlong addrGray1, jlong addrdescrptor)
{
    Mat& mGr1  = *(Mat*)addrGray1;
    Mat& descriptors_1 = *(Mat*)addrdescrptor;
    vector<KeyPoint> keypoint_1;

    //Do some processing here..

   return keypoint_1;
}
}

如果不是请建议我一些altenative的方式来实现这一目标。是新的OpenCV的。

If not please suggest me some altenative way to achieve it. am new in opencv.

推荐答案

我有同样的问题,我解决了它与这片code。

I had the same problem and I solved it with this piece of code.

首先在java中code的我已经声明了功能FindFeatures是这样的:

First of all in java code I've declared the function FindFeatures like this:

public native KeyPoint[] FindFeatures(long matAddrGr1, long matAddrGr2);

和我的祖国code是:

And my native code is:

JNIEXPORT jobjectArray JNICALL   Java_com_example_mipatternrecognition_Reconocimiento_FindFeatures(
    JNIEnv* env, jobject, jlong matAddrGr1, jlong matAddrGr2) {
    Mat& mGr = *(Mat*) matAddrGr1;
    Mat& mRgb = *(Mat*) matAddrGr2;
    vector < KeyPoint > keyPoints_1;

    //Do some processing...

    // Get a class reference for org/opencv/features2d/KeyPoint
    jclass cls = env->FindClass("org/opencv/features2d/KeyPoint");
    // Get the Method ID of the constructor (Float,Float,Float,Float,Float,Integer,Integer)
    jmethodID midInit = env->GetMethodID(cls, "<init>", "(FFFFFII)V");
    // Call back constructor to allocate a new instance
    jobjectArray newKeyPointArr = env->NewObjectArray(keyPoints_1.size(), cls, NULL);

    for (unsigned int i = 0; i < keyPoints_1.size(); i++) {
        jobject newKeyPoint = env->NewObject(cls, midInit, keyPoints_1[i].pt.x,
            keyPoints_1[i].pt.y, keyPoints_1[i].size, keyPoints_1[i].angle,
            keyPoints_1[i].response, keyPoints_1[i].octave,
            keyPoints_1[i].class_id);
        env->SetObjectArrayElement(newKeyPointArr, i, newKeyPoint);
    }

    return newKeyPointArr;
}

我希望它可以帮助你...

I hope it helps to you...

这篇关于入门从本地code关键点回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆