Требуется так много времени, чтобы получить ключевые точки и дескрипторы OpenCV
Я использовал метод OpenCV Surf для извлечения ключевых точек и дескрипторов, он работает нормально, но занимает так много времени.
Мой код: -
NSLog(@"Keypoint Detects");
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_1, keypoints_object );
detector.detect( img_2, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
NSLog(@"Descriptor Detects");
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( img_1, keypoints_object, descriptors_object );
extractor.compute( img_2, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
NSLog(@"Matching Detects");
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
Xcode результат времени: -
2015-10-26 13: 22: 27.282 AVDemo [288: 26112] Keypoint Detects
2015-10-26 13: 22: 28.361 AVDemo [288: 26112] Дескриптор обнаруживает
2015-10-26 13:22:30.077 AVDemo[288:26112] Соответствует обнаружению
Здесь требуется 2 секунды, чтобы вычислить
Я также использовал другой метод, чтобы получить как: -
NSLog(@"Detect Keypoints");
cv::Ptr<cv::BRISK> ptrBrisk = cv::BRISK::create();
ptrBrisk->detect(img_1, camkeypoints);
//for keypoints
NSLog(@"Compute Keypoints");
ptrBrisk->compute(img_1, camkeypoints,camdescriptors);
if(camdescriptors.type()!=CV_32F) {
camdescriptors.convertTo(camdescriptors, CV_32F);
}
NSLog(@"camera image conversion end");
Это также работает нормально, но имеет ту же проблему результата Time Xcode: -
2015-10-26 14: 19: 47.939 AVDemo [305: 32700] Определение ключевых точек
2015-10-26 14:19:49.787 AVDemo[305:32700] Вычисление ключевых точек
2015-10-26 14:19:49.818 AVDemo[305:32700] конец преобразования изображения с камеры
Как можно минимизировать это время?
Теперь я использовал FASTfeatureDetector, который минимизирует время, но все же SurfDescriptorExtractor требует времени.
Новый код:
NSLog(@"Keypoint Detects");
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 15;
FastFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_1, keypoints_object );
detector.detect( img_2, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
NSLog(@"Descriptor Detects");
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( img_1, keypoints_object, descriptors_object );
extractor.compute( img_2, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
NSLog(@"Matching Detects");
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
Xcode: -
2015-10-26 16: 06: 19.018 AVDemo [375: 47824] Обнаружение ключевой точки
2015-10-26 16:06:19.067 AVDemo[375:47824] Дескриптор обнаруживает
2015-10-26 16:06:21.117 AVDemo[375:47824] Соответствует обнаружению