前提・実現したいこと
OpenCVで二つの画像から特徴点を検出しマッチングするプログラムを作成しています。
マッチングから得られたkeypoint1,keypoint2のxy座標を指定して矢印の線で結びたいです。
発生している問題
opencvのarrowedLineを用いたのですがうまくできません。 arrowedLine(dst, Point(keypoint1[1].pt.x, keypoint1[1].pt.y), Point(keypoint2[1].pt.x, keypoint2[1].pt.y), (0, 0, 255), 8, LINE_4, 0, 0.3); 上記のPointの指定が間違っているのでしょうか?
該当のソースコード
C++
#include "stdafx.h" #include <opencv2/opencv.hpp> #pragma comment(lib, "opencv_world341d.lib") using namespace std; using namespace cv; int main() { Mat ref1(imread("62866.jpg")), ref2(imread("62865.jpg")); resize(ref1, ref1, cv::Size(), 0.3, 0.3); resize(ref2, ref2, cv::Size(), 0.3, 0.3); while (1) { // 特徴の抽出と記述 vector<KeyPoint> keypoint1, keypoint2; Mat descriptor1, descriptor2; Ptr<ORB> feature = ORB::create(); feature->detectAndCompute(ref1, noArray(), keypoint1, descriptor1); feature->detectAndCompute(ref2, noArray(), keypoint2, descriptor2); // 特徴点マッチング vector<DMatch> allMatch, goodMatch; BFMatcher matcher(NORM_HAMMING); matcher.match(descriptor1, descriptor2, allMatch); // 似ている特徴点ペアのみピックアップ for (int i = 0; i < (int)allMatch.size(); i++) { if (allMatch[i].distance < 30) goodMatch.push_back(allMatch[i]); } // 描画 Mat dst(480, 1280, CV_8UC3); drawMatches(ref1, keypoint1, ref2, keypoint2, goodMatch, dst, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); //DrawMatchesFlags::DRAW_RICH_KEYPOINTS); //DrawMatchesFlags::DEFAULT); //DrawMatchesFlags::DRAW_OVER_OUTIMG); arrowedLine(dst, Point(keypoint1[1].pt.x, keypoint1[1].pt.y), Point(keypoint2[1].pt.x, keypoint2[1].pt.y), (0, 0, 255), 8, LINE_4, 0, 0.3); ←ここ // 一致率 float matchRate = (float)goodMatch.size() / (float)keypoint1.size(); stringstream st; st.precision(3); st << fixed << matchRate; putText(dst, st.str(), Point(8, 24), FONT_HERSHEY_SIMPLEX, 1, 0, 2); if (matchRate > 0.01) putText(dst, "Detect", Point(650, 40), FONT_HERSHEY_SIMPLEX, 1.5, 0, 4); imshow("特徴点マッチング", dst); } }
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
Visual Studio 2017
OpenCV 3.4.1
まだ回答がついていません
会員登録して回答してみよう