我在使用 AutotunedIndexParams 进行 openCV 2.4.2 flann 索引时遇到问题。如果我使用多个图像来创建索引,程序将退出并输出:
trees : 1
terminate called throwing an exception
那是我在 JavaCV 中得到的相同代码的类似错误,其中错误如下:
trees : 1
Exception in thread "main" java.lang.RuntimeException: Missing parameter 'algorithm' in the parameters given
at com.googlecode.javacv.cpp.opencv_flann$Index.allocate(Native Method)
at com.googlecode.javacv.cpp.opencv_flann$Index.<init>(opencv_flann.java:229)
在 openCVs miniflann.cpp 中,我发现p["algorithm"]
设置了多行,这可能与问题有关吗?
为了在这里测试我的 C++ 代码,如果需要,我也会发布 java 代码;-)
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/flann/flann.hpp>
using namespace cv;
using namespace std;
using namespace flann;
int main( int argc, char** argv ) {
string pathToImages = "/Users/anubis/Desktop/KeypointTest/";
string img_1 = "book_001_canon.jpg";
string img_2 = "book_002_canon.jpg";
string img_3 = "book_003_canon.jpg";
string img_4 = "book_004_canon.jpg";
Mat db_image_1 = imread(pathToImages + img_1, CV_LOAD_IMAGE_COLOR);
Mat db_image_2 = imread(pathToImages + img_2, CV_LOAD_IMAGE_COLOR);
Mat db_image_3 = imread(pathToImages + img_3, CV_LOAD_IMAGE_COLOR);
Mat db_image_4 = imread(pathToImages + img_4, CV_LOAD_IMAGE_COLOR);
vector<KeyPoint> db_keypoints_1;
vector<KeyPoint> db_keypoints_2;
vector<KeyPoint> db_keypoints_3;
vector<KeyPoint> db_keypoints_4;
Mat db_descriptors_1;
Mat db_descriptors_2;
Mat db_descriptors_3;
Mat db_descriptors_4;
Mat db_descriptor;
SurfFeatureDetector detector(400, 4, 2, true, true);
SurfDescriptorExtractor extractor;
detector.detect(db_image_1, db_keypoints_1);
detector.detect(db_image_2, db_keypoints_2);
detector.detect(db_image_3, db_keypoints_3);
detector.detect(db_image_4, db_keypoints_4);
extractor.compute(db_image_1, db_keypoints_1, db_descriptors_1);
extractor.compute(db_image_2, db_keypoints_2, db_descriptors_2);
extractor.compute(db_image_3, db_keypoints_3, db_descriptors_3);
extractor.compute(db_image_4, db_keypoints_4, db_descriptors_4);
db_descriptor.push_back(db_descriptors_1);
db_descriptor.push_back(db_descriptors_2);
db_descriptor.push_back(db_descriptors_3);
db_descriptor.push_back(db_descriptors_4);
IndexParams indexParams = *new AutotunedIndexParams();
Index flannIndex = *new Index(db_descriptor, indexParams);
return 0;
}
图片可以在这里找到:图片