簡體   English   中英

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。 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存儲庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM