注册 登录
编程论坛 VC++/MFC

词袋模型中计算特征点(compute)出错

nicole_hf 发布于 2014-10-23 16:26, 895 次点击
错误如图:
[local]1[/local]
程序代码:
Mat dictionary,uDictionary;
    FileStorage fs("dictionary.yml", FileStorage::READ);
    fs["vocabulary"] >> dictionary;
    fs.release();   

    //create a nearest neighbor matcher
    Ptr<DescriptorMatcher> matcher(new FlannBasedMatcher);
    //create Sift feature point extracter
    Ptr<FeatureDetector> detector(new SiftFeatureDetector());
    //create Sift descriptor extractor
    Ptr<DescriptorExtractor> extractor(new SiftDescriptorExtractor);   
    //create BoF (or BoW) descriptor extractor
    BOWImgDescriptorExtractor bowDE(extractor,matcher);
    //Set the dictionary with the vocabulary we created in the first step

   
//dictionary.convertTo(uDictionary, CV_8UC1);

    cout<<"setVocabulary……"<<endl;
    bowDE.setVocabulary(dictionary);
    cout<<"setVocabulary over !"<<endl;
    //To store the image file name
    char * filename = new char[100];
    //To store the image tag name - only for save the descriptor in a file
    char * imageTag = new char[10];

    //open the file to write the resultant descriptor
    cout<<"file storing ……"<<endl;
    FileStorage fs1("descriptor.yml", FileStorage::WRITE);   
    cout<<"file storage over !"<<endl;
    //the image file with the location. change it according to your image file location
    sprintf(filename,"E:\\nicole_hf\\picture\\gps\\20141010_123726.jpg");        
    //read the image
    cout<<"filename:"<<filename<<endl;
    Mat img=imread(filename,CV_LOAD_IMAGE_GRAYSCALE);        
    //To store the keypoints that will be extracted by SIFT
    vector<KeyPoint> keypoints;
    //Detect SIFT keypoints (or feature points)
    detector->detect(img,keypoints);
    cout<<"--keypoints.size:"<<keypoints.size()<<endl;
    cout<<"detect over !"<<endl;
    //To store the BoW (or BoF) representation of the image
    Mat bowDescriptor;        
    //extract BoW (or BoF) descriptor from given image
    cout<<"computing……"<<endl;
    (img,keypoints,bowDescriptor);//----------------出错的地方----------------------

    cout<<"compute over !"<<endl;
    cout<<"--bowDescriptor:"<<bowDescriptor<<endl;
    //prepare the yml (some what similar to xml) file
    sprintf(imageTag,"img1");
    //write the new BoF descriptor to the file
    fs1 << imageTag << bowDescriptor;        

    //You may use this descriptor for classifying the image.

   
//release the file storage
    fs1.release();
3 回复
#2
nicole_hf2014-10-23 16:30
额 图片显示不出来,重新贴上来哈,错误信息如下:
Assertion failed: queries.cols == veclen()
#3
walikb2014-10-25 20:20
回复 2 楼 nicole_hf
你好,我也遇到了这个问题,请问你解决了么?我的扣扣63462889,希望能交流一下解决办法
#4
nicole_hf2015-01-05 18:11
额  不好意思  好久没上来了  没看到  是因为OpenCV版本的问题  低版本的OpenCV里面的compute方法里面是空的  换个高版本的就可以了  我之前用的是OpenCV2.2  后来换成OpenCV4.6就好了
1