0
私は画像間の一致を検索するには、次のコードを使用しています:OpenCVの3.1の機能が変更されたのでOpenCV 3.1で検出されたオブジェクトをSIFT機能で描画する方法は?
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <vector>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
//cv::initModule_nonfree();
//initModule_features2d();
Mat img_1 = imread("C:/Users/Dan/Desktop/0.jpg", 1);
Mat img_2 = imread("C:/Users/Dan/Desktop/0.jpg", 1);
cv::Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
//-- Step 1: Detect the keypoints:
std::vector<KeyPoint> keypoints_1, keypoints_2;
f2d->detect(img_1, keypoints_1);
f2d->detect(img_2, keypoints_2);
//-- Step 2: Calculate descriptors (feature vectors)
Mat descriptors_1, descriptors_2;
f2d->compute(img_1, keypoints_1, descriptors_1);
f2d->compute(img_2, keypoints_2, descriptors_2);
Mat out0;
drawKeypoints(img_1, keypoints_1, out0);
imshow("KeyPoint0.jpg", out0);
//-- Step 3: Matching descriptor vectors using BFMatcher :
BFMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
Mat img_matches = Mat::zeros(img_1.size(), CV_8UC3);
drawMatches(img_1,keypoints_1,img_2,keypoints_2,matches,img_matches);
imshow("matches", img_matches);
waitKey(0); // Keep window there until user presses 'q' to quit.
return 0;
}
、私はSURFを使用するか、私の場合にはSIFTされるサンプルコードを探していましたが、私はできませんでした何かを見つける。
in the code of the other version of OpenCVのような検出されたオブジェクトの周りに輪郭を描くようにコードの完成を助けてくれますか?
ありがとう、ダン。
あなたが検出する画像にあなたのトレーニング画像(img_1)の関係変換(img_2)を取得するためにfindHomography
を使用する必要があります
http://docs.opencv.org/trunk/d7/dff/から採取された検出画像
関連コードの正しい境界ボックスを配置するために、得られたホモグラフィを使用してtutorial_feature_homog raphy.html#gsc.tab = 0 – Miki