Opencv3.1.0 findHomography返回空矩阵

时间:2016-05-12 13:35:40

标签: c++ opencv computer-vision

我正在处理图像注册问题。

我正在使用opencv3.1.0的findHomography函数来获得单应性。问题是,即使使用不同的图像,我总是得到一个空矩阵。 我尝试了不同的功能描述符,如ORB,BRISK。这只发生在ORB上。但我必须使用ORB。

那么......为什么我得到一个空矩阵?我怎样才能得到一个好的单应矩阵?谢谢:))

Ptr<ORB> ptrORB = ORB::create(2000);
ptrORB->detect(img1, kpts1);           //use ORB as detector
ptrORB2->detect(img2, kpts2);

Ptr<BRISK> ptrBrisk = BRISK::create(); //use BRISK as descriptor
ptrBrisk->compute(img1, kpts1, desp1);
ptrBrisk->compute(img2, kpts2, desp2);

//Nearest neighbour ratio matching
double ratio = 0.8;
vector<vector<DMatch>> nnMatches;
vector<DMatch> matches;
BFMatcher matcher;
matcher.knnMatch(desp1, desp2, nnMatches, 2);
for (int k = 0; k < nnMatches.size(); k++) {
    if (nnMatches[k][0].distance / nnMatches[k][1].distance < ratio) {
        matches.push_back(nnMatches[k][0]);
    }
} 

//Homography
std::vector<Point2f> points1;
std::vector<Point2f> points2;

for (int i = 0; i < matches.size(); i++) {
    points1.push_back(kpts1[matches[i].queryIdx].pt);
    points2.push_back(kpts2[matches[i].trainIdx].pt);
}

Mat H = findHomography(points1, points2, RANSAC);

0 个答案:

没有答案