词袋模型中计算特征点(compute)出错
错误如图:[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();