Я пытаюсь понять, как вектор fisher работает с SIFT в Opencv3.0 и библиотеке VLFeat. но я получил пустой вектор и конец. Я не уверен, где я сделал неправильно, или моя логика была неправильной?
Возможно ли, если кто-то знает об этом? Ценю за ваши советы. вот мой код, как показано ниже:
int main(int argc, char** argv)
{
int num_clusters = 15; //subject to change
Ptr<FeatureDetector> detector = xfeatures2d::SIFT::create(400);
Ptr<DescriptorExtractor> extractor = xfeatures2d::SIFT::create();
vector<KeyPoint> keypoints;
Mat descriptors, img;
Point2f loc;
//Define for GMM train
Mat labels, posterior,logLikelihood;
Ptr<EM> em_model = EM::create();
em_model->setClustersNumber(num_clusters);
em_model->setCovarianceMatrixType(EM::COV_MAT_DIAGONAL);
em_model->setTermCriteria(TermCriteria(TermCriteria::EPS+TermCriteria::MAX_ITER,100, 0.1 ));
string filename = "21.jpg";
//local keypoint descriptor based on ORB
img = imread(filename, CV_LOAD_IMAGE_COLOR);
detector->detect(img, keypoints);
extractor->compute(img, keypoints, descriptors); //**
cout << "Discriptor Dimension: " << descriptors.rows << endl;
cout << "Training GMM... " << flush;
em_model->trainEM(descriptors, logLikelihood, labels, posterior);
cout << "Done!" << endl;
// extract gaussian information
Mat means = em_model->getMeans(); //r10nc c2
vector<Mat> covs; // 10nc [2:2]//covariance matric
em_model->getCovs(covs); //Returns covariation matrices, size = num 2x2 gaussian
// extract covariance matrix
Mat covariaceMatrix;
for (int itk =0; itk < num_clusters; itk++)
{
Mat coVR = Mat(covs[itk]);
covariaceMatrix.push_back(coVR);
}
cout<< "Covariance Matrix \n" << covariaceMatrix << endl;
Mat weights = em_model->getWeights(); //r1 c30nc
//define vector to store vector ans
Mat fvlist;
//descriptor/centroid?
Mat *dataToEncode = &descriptors;
vl_size dimension = descriptors.rows;
vl_size numClusters = num_clusters;
//nb of dimensions to keep in local descriptors
vl_size numData = 64;
vl_size numDataToEncode = 128;
//nb of dimensions to keep after Fisher descriptor is projected
//create a new instance of a GMM object for float data
VlGMM* gmm = vl_gmm_new(VL_TYPE_FLOAT, dimension, numClusters);
// cluster the data, i.e. learn the GMM
vl_gmm_cluster(gmm, &dataToEncode, numData);
// allocate space for the encoding
void* enc = vl_malloc(sizeof(float) * 2 * dimension * numClusters);
// run fisher encoding
vl_fisher_encode(enc, VL_TYPE_FLOAT, vl_gmm_get_means(gmm), dimension,
numClusters, vl_gmm_get_covariances(gmm), vl_gmm_get_priors(gmm),
&dataToEncode, numDataToEncode, VL_FISHER_FLAG_IMPROVED);fvlist.push_back(enc);
vl_free(enc);
vl_gmm_delete(gmm);
cout << "Fisher Vector\n" << fvlist;return 0;
}
Задача ещё не решена.
Других решений пока нет …