添加SurfFeatureDetector后,程序给出错误

After adding SurfFeatureDetector, program giving error

本文关键字:出错 错误 程序 SurfFeatureDetector 添加      更新时间:2023-10-16

我正在使用opencv 3.3.0

我的代码是

#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <fstream>
#include <string>
#include <vector>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main(int argc, char** argv)
{
    Mat img1;
    img1 = imread("img/img1.jpg", IMREAD_GRAYSCALE);
    if (img1.empty())
    {
        cout << "Could not open or find the image" << endl;
        return -1;
    }
    Ptr<SurfFeatureDetector> detector = SurfFeatureDetector::create(400);
    vector<KeyPoint> keypoints;
    detector->detect(img1, keypoints);
    imshow("img1", img1);
    waitKey(0);
    return 0;
}

我是C++opencv新手.代码在没有冲浪部分的情况下运行良好。

错误

OpenCV Error: Assertion failed (TlsSetValue(tlsKey, pData) == TRUE) in cv::TlsAbstraction::SetData, file C:\Users\Darshana\Documents\opencv\opencv-3.3.0\modules\core\src\system.cpp, 第 1270 行

我也尝试过Ptr<SURF> detector = SURF::create(400);

更新

我无法为此找到解决方案。可能是设置问题或库问题。所以我只是搬到opencv 2.4.13,现在一切正常。不过,我不得不更改上面的代码才能使用v2.4.13

您尚未为 SurfFeatureDetector 设置参数。我认为你应该试试这个:

int minHessian = 400;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints;
detector.detect(img1, keypoints);
相关文章: