キーポイントと記述子を取得するために 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] キーポイント検出
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] 一致検出