gpt4 book ai didi

android - 从 native 代码中获取关键点

转载 作者:行者123 更新时间:2023-12-02 16:49:52 25 4
gpt4 key购买 nike

我正在使用 opencv-sdk-android。
我希望我的 native 代码应该返回关键点向量。使用这样的代码是否正确..
Vector<KeyPoint> keypoint = FindFeatures(Gray1.getNativeObjAddr(),descriptor.getNativeObjAddr());

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

我的 natice 代码是
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;
}
}

如果没有,请建议我一些替代方法来实现它。我是opencv的新手。

最佳答案

我有同样的问题,我用这段代码解决了它。

首先在java代码中我声明了这样的函数FindFeatures:

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

我的 native 代码是:
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;
}

我希望它对你有帮助...

关于android - 从 native 代码中获取关键点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20403726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com