OpenCV 4.13.0
Open Source Computer Vision
読み込み中...
検索中...
見つかりません
🤖 AIによる機械翻訳(非公式) — これは OpenCV 4.13.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
平面物体の検出

前のチュートリアル: Features2D + Homography to find a known object
次のチュートリアル: AKAZE局所特徴のマッチング

原著者Victor Eruhimov
互換性OpenCV >= 3.0

このチュートリアルの目的は、シーン内の既知の平面オブジェクトを検出するために features2d モジュールと calib3d モジュールの使い方を学ぶことである。

テストデータ: データフォルダ内の画像を使用する。例えば box.png と box_in_scene.png など。

  • 新しいコンソールプロジェクトを作成する。2枚の入力画像を読み込む。 :
    Mat img1 = imread(argv[1], IMREAD_GRAYSCALE); Mat img2 = imread(argv[2], IMREAD_GRAYSCALE); 
  • 両方の画像でキーポイントを検出し、各キーポイントの記述子を計算する。 :
    // detecting keypoints Ptr<Feature2D> surf = SURF::create(); vector<KeyPoint> keypoints1; Mat descriptors1; surf->detectAndCompute(img1, Mat(), keypoints1, descriptors1); ... // do the same for the second image 
  • 次に、1枚目の画像の記述子から2枚目の画像の記述子へ最も近いマッチを探す: :
    // matching descriptors BruteForceMatcher<L2<float> > matcher; vector<DMatch> matches; matcher.match(descriptors1, descriptors2, matches); 
  • 結果を可視化する: :
    // drawing the results namedWindow("matches", 1); Mat img_matches; drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches); imshow("matches", img_matches); waitKey(0); 
  • 2つの点群間のホモグラフィ変換を求める: :
    vector<Point2f> points1, points2; // fill the arrays with the points .... Mat H = findHomography(Mat(points1), Mat(points2), RANSAC, ransacReprojThreshold); 
  • インライアのマッチ集合を作成し、それらを描画する。perspectiveTransform関数を使ってホモグラフィで点を変換する:

    Mat points1Projected; perspectiveTransform(Mat(points1), points1Projected, H);

  • インライアの描画には drawMatches を使う。