gpt4 book ai didi

android - detectAndCompute() 中发生错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:54 26 4
gpt4 key购买 nike

当我在调试器下运行我的代码时,它显示了一个 <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");
}

}

最佳答案

要缩小范围,请尝试将 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

关于android - <unknown> detectAndCompute() 中发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54966701/

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