<unknown> Произошла ошибка в detectAndCompute () - PullRequest
0 голосов
/ 03 марта 2019

Когда я запускал свой код в отладчике, он показывал ошибку <unknown> в:

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

вот так this

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

Java-код в:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) 

и это не равно нулю.

Это часть 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;
        }
    }
}

РЕДАКТИРОВАТЬ

Вот мой пример входного изображения A image

Это изображение, связанное с кодом.Я отправляю изображения из каталога asset в JNI, используя код java.

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 Ответ

0 голосов
/ 03 марта 2019

Чтобы сузить его, попробуйте разделить detectAndCompute() на detect() и 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 );        
...
}

ссылки:

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

...