<unknown> Error occured in detectAndCompute()

问题: When I ran my code under debugger, it showed an <unknown> error in: detector->detectAndCompute( matInput, noArray(), keypoints2, descriptors2 ); like this...

问题:

When I ran my code under debugger, it showed an <unknown> error in:

detector->detectAndCompute( matInput, noArray(), keypoints2, descriptors2 );

like this this

`matInput` is from `inputFrame.rgba()` 

Java code in :

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) 

and this is not null.

This is a part of native-lib.cpp:

std::vector<Mat> trainImages;

std::vector< std::vector<DMatch> > knn_matches;
std::vector<KeyPoint> keypoints1;
std::vector<KeyPoint> keypoints2;

Mat matImg;

static void createKeypointsAndDescriptors(const Mat& matInput) {

    int minHessian = 400;
    cv::Ptr<SURF> detector = SURF::create( minHessian ); 
    std::vector<KeyPoint> temp_keypoints;
    std::vector<std::vector<KeyPoint>> temp_keypoints1;
    Mat temp_descriptors;
    std::vector<Mat> temp_descriptors1;
    Mat descriptors2;
    std::vector< std::vector<DMatch> > temp_knn_matches;

    for(int i = 0; i < 2; i++) {
        detector->detectAndCompute( trainImages[i], noArray(), temp_keypoints, temp_descriptors );
        temp_keypoints1.push_back(temp_keypoints);
        temp_descriptors1.push_back(temp_descriptors);
    }

    detector->detectAndCompute( matInput, noArray(), keypoints2, descriptors2 );        

    Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);
    int max = 0;

    for(int i = 0; i < 2; i++) {

        if(temp_keypoints[i].size >= 2 && keypoints2.size() >= 2)
            matcher->knnMatch( temp_descriptors1[i], descriptors2, temp_knn_matches, 2 );

        if(max < temp_knn_matches.size()) {
            max = temp_knn_matches.size();
            keypoints1 = temp_keypoints1[i];
            matImg = trainImages[i];
            knn_matches = temp_knn_matches;
        }
    }
}

EDIT

Here's my example input image A image

This is a code related image. I send images from the asset directory to JNI by using java code.

extern "C"
JNIEXPORT void JNICALL
Java_com_example_surfwithflann2_MainActivity_sendImages(JNIEnv *env, jobject instance,
                                                       jlongArray tempAddrObj_) {

    if(trainImages.size() == 0) {
        int length = env->GetArrayLength(tempAddrObj_);
        jlong *tempAddrObj = env->GetLongArrayElements(tempAddrObj_, NULL);

        for(int i = 0; i < length; i++) {
            cv::Mat &tempImage = *(cv::Mat *)tempAddrObj[i];
            trainImages.push_back(tempImage);
        }
        env->ReleaseLongArrayElements(tempAddrObj_, tempAddrObj, 0);
    } else {
        __android_log_print(ANDROID_LOG_DEBUG, "TAG", "already received from java");
    }

}

回答1:

To narrow it down, try splitting detectAndCompute() into detect() and compute():

#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace cv::xfeatures2d;

std::vector<cv::KeyPoint> keypoints2;
cv::Mat descriptors2;

static void createKeypointsAndDescriptors(const cv::Mat& matInput) {
  //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
    double minHessian = 400;
    Ptr<SURF> detector = SURF::create();
    detector->setHessianThreshold(minHessian);

    detector->detect(matInput, keypoints2);
    detector->compute(matInput, keypoints2, descriptors2);
    // detector->detectAndCompute( matInput, noArray(), keypoints2, descriptors2 );        
...
}

links:

cv::xfeatures2d::SURF Class Reference
cv::Feature2D Class Reference
cv::xfeatures2d::AffineFeature2D Class Reference

  • 发表于 2019-03-05 13:38
  • 阅读 ( 159 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除