質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

9200閲覧

特徴点検出 検出した特徴点の座標を表示する方法について

yezyez

総合スコア13

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2018/12/27 07:14

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]の中に格納されていると思うのですがどのようにかけばいいのかがわかりません

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

DMatch クラスの以下のメンバ変数がキーポイントのインデックスなので、これを参照すればよいです。

DMatch.trainIdx - train 画像の特徴量記述子のインデックス
DMatch.queryIdx - query 画像の特徴量記述子のインデックス

詳しくは以下の質問参照
https://teratail.com/questions/165142#reply-246420

投稿2018/12/27 07:17

tiitoi

総合スコア21956

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yezyez

2018/12/27 07:41

ありがとうございます。座標点を出すことができました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問