Sorunu doğru bir şekilde anladıysam, anahtar noktasını, OpenCV cv::drawMatches
ile çizim yapmak veya benzer OpenCV işleviyle kullanmak amacıyla std::vector<cv::DMatch>
numaralı anahtarda eşleşmesini istediğinizi varsayalım. için maçları hakkında dolgun bilgi gerekiyorsa,
const cv::Mat& pic1 = img_1_var;
const cv::Mat& pic2 = img_2_var;
const std::vector <cv::KeyPoint> &feats1 = img_1_feats;
const std::vector <cv::KeyPoint> &feats2 = img_2_feats;
// you of course can work directly with original objects
// but for drawing you only need const references to
// images & their corresponding extracted feats
std::vector <std::pair <int, int> > aMatches;
// fill aMatches manually - one entry is a pair consisting of
// (index_in_img_1_feats, index_in_img_2_feats)
// the next code draws the matches:
std::vector <cv::DMatch> matches;
matches.reserve((int)aMatches.size());
for (int i=0; i < (int)aMatches.size(); ++i)
matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second,
std::numeric_limits<float>::max()));
cv::Mat output;
cv::drawMatches(pic1, feats1, pic2, feats2, matches, output);
cv::namedWindow("Match", 0);
cv::setWindowProperty("Match", CV_WINDOW_FULLSCREEN, 1);
cv::imshow("Match", output);
cv::waitKey();
cv::destroyWindow("Match");
Alternatif olarak: Ben de "elle" eşleşmesini yapıyordu yana son zamanlarda, burada keyfi maçları bir std::vector<std::pair <int, int> > aMatches
orijinal içerdiği yukarı çeker ve bir pencerede görüntüler kod bu çizim yapmaktan daha karmaşıktır, o zaman eşleşme arasındaki mesafeyi uygun bir değere ayarlamak isteyebilirsiniz. Örneğin. Bununla
for (int i=0; i < (int)aMatches.size(); ++i)
matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second,
std::numeric_limits<float>::max()));
(bunun için nota, aynı zamanda ihtiyaç duyulan açıklayıcı vektörleri özelliği bir referans):
cv::L2<float> cmp;
const std::vector <std::vector <float> > &desc1 = img_1_feats_descriptors;
const std::vector <std::vector <float> > &desc2 = img_2_feats_descriptors;
for (int i=0; i < (int)aMatches.size(); ++i){
float *firstFeat = &desc1[aMatches[i].first];
float *secondFeat = &desc2[aMatches[i].second];
float distance = cmp(firstFeat, secondFeat, firstFeat->size());
matches.push_back(cv::DMatch(aMatches[i].first, aMatches[i].second,
distance));
}
Eğer
L2 mesafeyi kullanarak mesafeleri hesaplamak istiyorsanız, aşağıdaki satırı değiştirmeniz gerekir
Son parçacıkta, descX[i]
, featsX[i]
için bir tanımlayıcı olduğunu, iç vektörün her öğesinin, tanımlayıcı vektörün bir bileşeni olduğunu unutmayın. Ayrıca, tüm tanımlayıcı vektörlerin aynı boyutlara sahip olması gerektiğini unutmayın.
Gelecekte başvurmak için, sorularınızı daha net hale getirmeye çalışmalısınız. Örneğimi "hangi çiftlerin bir araya geleceğini biliyorum" ve "std :: vector" ile temellendirdim. Cevabın herhangi bir ek açıklamasına ihtiyacınız varsa, lütfen soruyla daha kesin olmaya çalışın. –
penelope