首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 ><unknown>错误在detectAndCompute()中发生

<unknown>错误在detectAndCompute()中发生
EN

Stack Overflow用户
提问于 2019-03-03 07:52:38
回答 1查看 165关注 0票数 1

当我在调试器下运行代码时,它显示了一个<unknown>错误:

代码语言:javascript
运行
复制
detector->detectAndCompute( matInput, noArray(), keypoints2, descriptors2 );

像这样

代码语言:javascript
运行
复制
`matInput` is from `inputFrame.rgba()` 

Java代码,在:

代码语言:javascript
运行
复制
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) 

这并不是空的。

这是native-lib.cpp的一部分

代码语言:javascript
运行
复制
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;
        }
    }
}

编辑

这是我的输入图像示例

这是一个与代码相关的图像。我使用asset代码从JNI目录向java发送图像。

代码语言:javascript
运行
复制
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");
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-03 08:56:01

若要缩小范围,请尝试将detectAndCompute()拆分为detect()compute()

代码语言:javascript
运行
复制
#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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54966701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档