Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mixed raw pointers and Ptr<> in features2d java wrappers #11268

Closed
@berak

Description

@berak
System information (version)
  • OpenCV => 3.4.1-dev (master)
  • Operating System / Platform => Windows 64 Bit
  • Compiler => ming64
Detailed description

bothFlannBasedMatcher andBFMatcher have a public constructor and a create() method, the 1st constructs a new FlannBasedMatcher , the 2nd anew Ptr<Ptr<FlannbasedMatcher>>.
since the internal wrapper code expects the latter, using an instance created from a constructor will segfault
when being deferenced like this:

  Ptr<cv::DescriptorMatcher>* me = (Ptr<cv::DescriptorMatcher>*) self;

a similar problem occurs in theBOWKMeansTrainer class, which can only be invoked from a constructor, but the internal code uses dereferencedPtr

java example code:

FlannbasedMatcher matcher = new FlannbasedMatcher();matcher.match(descriptor1, descriptor2, matches); // segfaultsBOWKMeansTrainer trainer = new BOWKMeansTrainer(100);Mat vocab = trainer.cluster(descriptors); // segfaults

generated jni code:

JNIEXPORT jlong JNICALL Java_org_opencv_features2d_FlannBasedMatcher_FlannBasedMatcher_10  (JNIEnv* env, jclass ){    static const char method_name[] = "features2d::FlannBasedMatcher_10()";    try {        LOGD("%s", method_name);                cv::FlannBasedMatcher* _retval_ = new cv::FlannBasedMatcher( makePtr<flann::KDTreeIndexParams>(), makePtr<flann::SearchParams>() );        return (jlong) _retval_;    } catch(const std::exception &e) {        throwJavaException(env, &e, method_name);    } catch (...) {        throwJavaException(env, 0, method_name);    }    return 0;}JNIEXPORT void JNICALL Java_org_opencv_features2d_DescriptorMatcher_knnMatch_11  (JNIEnv* env, jclass , jlong self, jlong queryDescriptors_nativeObj, jlong trainDescriptors_nativeObj, jlong matches_mat_nativeObj, jint k){    static const char method_name[] = "features2d::knnMatch_11()";    try {        LOGD("%s", method_name);        std::vector< std::vector<DMatch> > matches;        Mat& matches_mat = *((Mat*)matches_mat_nativeObj);        Ptr<cv::DescriptorMatcher>* me = (Ptr<cv::DescriptorMatcher>*) self; //TODO: check for NULL        Mat& queryDescriptors = *((Mat*)queryDescriptors_nativeObj);        Mat& trainDescriptors = *((Mat*)trainDescriptors_nativeObj);        (*me)->knnMatch( queryDescriptors, trainDescriptors, matches, (int)k );        vector_vector_DMatch_to_Mat( matches, matches_mat );        return;    } catch(const std::exception &e) {        throwJavaException(env, &e, method_name);    } catch (...) {        throwJavaException(env, 0, method_name);    }    return;}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp