![]() |
OpenCV 5.0.0
Open Source Computer Vision
|
前のチュートリアル: 特徴 + ホモグラフィによる既知物体の検出
次のチュートリアル: AKAZE 局所特徴のマッチング
| 原著者 | Victor Eruhimov |
| 互換性 | OpenCV >= 3.0 |
このチュートリアルの目的は、シーン内の既知の平面物体を検出するために features モジュールと calib3d モジュールの使い方を学ぶことである。
テストデータ: データフォルダ内の画像を使用する。例えば box.png と box_in_scene.png など。
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
// 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); 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);