mardi 29 décembre 2015

OpenCV3, SIFT compute with vector

According to the document, SIFT object could use the function below to compute descriptors for multiple images:

virtual void compute (InputArrayOfArrays images, std::vector< std::vector< KeyPoint > > &keypoints, OutputArrayOfArrays descriptors)

I'm trying to compute the SIFT descriptors for multiple images with the code below:

Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
vector<vector<KeyPoint>> train_keypoints;
f2d->detect(train_imgs, train_keypoints);

vector<Mat> train_descriptors;
f2d->compute(train_imgs, train_keypoints, train_descriptors);

It could be compiled under Mac OS 10.10.5 with opencv3, while it might terminate during execution with error:

libc++abi.dylib: terminating with uncaught exception of type std::length_error: vector

Or I could change the type of train_descriptors into Mat (instead of vector< Mat >), it'll still fail during execution with another error:

OpenCV Error: Assertion failed (_descriptors.kind() == _InputArray::STD_VECTOR_MAT) in compute, file /tmp/opencv320151228-32931-2p5ggk/opencv-3.1.0/modules/features2d/src/feature2d.cpp, line 126 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv320151228-32931-2p5ggk/opencv-3.1.0/modules/features2d/src/feature2d.cpp:126: error: (-215) _descriptors.kind() == _InputArray::STD_VECTOR_MAT in function compute

What type of train_descriptors should I use to make this code compile and run correctly?

Aucun commentaire:

Enregistrer un commentaire