c++
1#include <opencv2/highgui/highgui.hpp> 2#include <opencv2/imgproc/imgproc.hpp> 3#include <opencv2/features2d/features2d.hpp> 4#include <opencv2/calib3d/calib3d.hpp> 5#include <opencv2/xfeatures2d/nonfree.hpp> 6#include <iostream> 7 8using namespace cv; 9using namespace std; 10 11int main(void) 12{ 13 14 int idx[2000]; 15 int x,y,i = 0; 16 int x2,y2,i2 = 0; 17 int x3,y3 = 0; 18 int x4,y4 = 0; 19 int i5,i6 = 0; 20 21 // 画像の読み込み 22 Mat img_src1 = imread( "left.jpg" ); 23 Mat img_src2 = imread( "right.jpg" ); 24 25 // 画像の表示 26 imshow( "leftcamera", img_src1); 27 imshow( "rightcamera", img_src2); 28 waitKey( 0 ); 29 30 auto akaze = AKAZE::create(); 31 32 vector<KeyPoint> keypoints1,keypoints2; 33 akaze->detect(img_src1,keypoints1); 34 akaze->detect(img_src2,keypoints2); 35 36 // 特徴点の座標、大きさを表示keypoint1 37 vector<KeyPoint>::iterator it = keypoints1.begin(), it_end = keypoints1.end(); 38 for(;it != it_end;it++) { 39 i++; 40 x = it->pt.x; 41 y = it->pt.y; 42 cout << "keypoint1 " << i << " x=" << x << " y=" << y << "\n"; 43 } 44 // 特徴点の座標、大きさを表示keypoint2 45 vector<KeyPoint>::iterator it2 = keypoints2.begin(), it2_end = keypoints2.end(); 46 for(;it2 != it2_end;it2++) { 47 i2++; 48 x2 = it2->pt.x; 49 y2 = it2->pt.y; 50 cout << "keypoint2 " << i2 << " x=" << x2 << " y=" << y2 << "\n"; 51 } 52 53 Mat descriptor1, descriptor2; 54 akaze->compute(img_src1, keypoints1, descriptor1); 55 akaze->compute(img_src2, keypoints2, descriptor2); 56 57 //DescriptorMatcherオブジェクトの生成 58 Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce"); 59 // 特徴点のマッチング情報を格納する変数 60 vector<DMatch> dmatch, match; 61 // 特徴点マッチングの実行 62 matcher->match(descriptor1, descriptor2, match); 63 64 // 最小距離の取得 65 double min_dist = DBL_MAX;//double の最大値 66 for (int i = 0; i < (int)match.size(); i++){ 67 double dist = match[i].distance;//画像間の特徴点距離 68 69 //特徴点間の最小距離を求める 70 if (dist < min_dist){ 71 min_dist = dist; 72 } 73 } 74 if (min_dist < 1.0) 75 { 76 min_dist = 1.0; 77 } 78 79 // しきい値を設定する 80 const double threshold = 5.0 * min_dist; 81 82 for (int i = 0; i < (int)match.size(); i++){ 83 if (match[i].distance < threshold){ 84 idx[i] = 1; 85 dmatch.push_back(match[i]); 86 }else{ 87 idx[i] = -1; 88 } 89 } 90 91 vector<DMatch>::iterator it5 = dmatch.begin(), it5_end = dmatch.end(); 92 for (int i = 0; i < (int)match.size(); i++){ 93 if(idx[i] != -1){ 94 i5++; 95 cout << "dmatch " << i5 << " "; 96 /* 画像1の対応点座標 */ 97 x3 = keypoints1[i].pt.x; 98 y3 = keypoints1[i].pt.y; 99 for(;it5 != it5_end;it5++) { 100 i6++; 101 /* 画像2の対応点座標 */ 102 x4 = keypoints2[dmatch[i6]].pt.x; 103 y4 = keypoints2[dmatch[i6]].pt.y; 104 //座標表示 105 cout << "keypoint1 " << " x=" << x3 << " y=" << y3 << " " << "keypoint2 " << " x=" << x4 << " y=" << y4 << "\n"; 106 } 107 } 108 } 109 110 111 Mat dest; 112 drawMatches(img_src1, keypoints1, img_src2, keypoints2, dmatch, dest); 113 114 imshow("result",dest); 115 waitKey( 0 ); 116 117 return 0; 118}
左右の対応した画像の座標値を書き出したいのですが
/* 画像1の対応点座標 /
x3 = keypoints1[i].pt.x;
y3 = keypoints1[i].pt.y;
の箇所で画像1の座標値は取り出すことができましたが、
/ 画像2の対応点座標 */
x4 = keypoints2[dmatch[i6]].pt.x;
y4 = keypoints2[dmatch[i6]].pt.y;
の箇所で画像2の座標値を取り出すことができません、keypoint1[i]に対応するkeypoint2[i]の位置はmatch[i]の中に格納されていると思うのですがどのようにかけばいいのかがわかりません

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/27 07:41