OpenCV 3.0分词故障(视觉词袋)
OpenCV 3.0 Segmentation Fault (Bag of visual words)
我正在尝试使用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。现在,您得到了空指针实例(这是您的段错误)。
#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,因此需要为这个
相关文章:
- 分段故障(堆芯转储)矢量
- C++中的动态铸造故障
- 数组的指针从不分段故障
- vscode g++链路故障:体系结构x86_64的未定义符号
- 访问被拒绝后,c++中的故障保护代码
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 视觉studo 2019中的漫画和静态/动态绑定
- 如何改变c++应用程序的视觉效果
- 视觉工作室项目.提取源文件夹名称
- 调试 CUDA MMU 故障
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 视觉我希望一个函数在另一个函数C++中进行计算
- 视觉 如何循环访问C++中遵循类似格式的多个.txt文件?
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- remove(str.begin(), str.end(), );无法正常工作(我正在使用视觉工作室 2012)
- 正在处理故障(堆芯转储)
- C++快板视觉故障
- OpenCV 3.0分词故障(视觉词袋)