gpt4 book ai didi

c++ - OpenCV 3.0 分割错误(Bag of visual words)

转载 作者:行者123 更新时间:2023-11-28 02:24:15 26 4
gpt4 key购买 nike

我正在尝试使用 openCV 3.0 设置一组视觉词。我到处找了一下,似乎只能找到只与 2.x 域中的版本兼容的代码。截至目前,这就是我所拥有的:

#include <opencv2/core/core.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>

#include <iostream>
#include <stdio.h>


using namespace std;
using namespace cv;

int main(int argc, const char** argv) {

Ptr<FeatureDetector> features;
Ptr<DescriptorExtractor> descriptors;
Ptr<DescriptorMatcher> matcher;

int MAX_ITER = 100;
int EPS = 2;

TermCriteria tc(MAX_ITER + EPS,1,0.001);

int dictSize = 1000;
int retries = 1;
int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(dictSize,tc,retries,flags);

BOWImgDescriptorExtractor bowDE(descriptors,matcher);



Mat img1 = imread("/Users/Lucas/Desktop/pic2.jpg");
Mat img2 = imread("/Users/Lucas/Desktop/2.jpg");

vector<KeyPoint> keypoints,keypoints2;
features->detect(img1, keypoints);
features->detect(img2, keypoints2);


Mat myFeatures;
Mat myFeatures2;

descriptors->compute(img1, keypoints, myFeatures);
descriptors->compute(img2, keypoints2, myFeatures2);
bowTrainer.add(myFeatures);
bowTrainer.add(myFeatures2);

Mat dictionary = bowTrainer.cluster();
bowDE.setVocabulary(dictionary);

cout << dictionary << endl;


return 0;
}

我已使用一些教程和片段将其整合在一起,但我遇到了一个问题。当程序到达

features->detect(img1, keypoints);

它以段错误 11 退出,不管那是什么意思。有人可以帮助我并指出我做错了什么吗?

最佳答案

您必须先创建您的 FeatureDetector、DescriptorExtractor。 atm,你有空指针实例(那是你的段错误)。

   #include <opencv2/xfeatures2d.hpp>
...

Ptr<FeatureDetector> features = xfeatures2d::SIFT::create();
Ptr<DescriptorExtractor> descriptors = xfeatures2d::SIFT::create();
Ptr<DescriptorMatcher> matcher = makePtr<BFMatcher>(NORM_L2);

请注意,由于您必须使用 SIFT 或 SURF,因此您需要 opencv_contrib repo为此安装

关于c++ - OpenCV 3.0 分割错误(Bag of visual words),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31265180/

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