【发布时间】:2013-05-17 13:14:03
【问题描述】:
我使用 OpenCV 2.4.5。我想在两个图像的匹配点之间画线。代码是:
const int &w=image1.cols;
for (size_t i = 0; i<good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
img1.push_back(keypoints1[good_matches[i].queryIdx].pt);
img2.push_back(keypoints2[good_matches[i].trainIdx].pt);
circle(image1,img1[i],20,Scalar(255,0,0),5);
circle(image2,img2[i],20,Scalar(0,255,0),5);
line(image1,img1[i],Point2f(img2[i].x+w,img2[i].y),Scalar(255,255,255),5);
line(image2,Point2f(img1[i].x-w,img1[i].y),img2[i],Scalar(255,255,255),5);
}
当within the bounds of image 的行长度大于16400 时,我得到奇怪的结果。它看起来像线的三角形或有时在 2 个对应点之间的虚线,而不是点之间的直线。
所以我应该画线段而不是总线。但这不是很方便。是因为画线算法的限制还是可以通过某种方式纠正?
【问题讨论】:
-
也许您可以使用内置函数
drawMatches。 docs.opencv.org/modules/features2d/doc/… drawMatches(const Mat& img1, const vector& keypoints1, const Mat& img2, const vector & keypoints2, const vector &matches1to2, Mat& outImg, const Scalar& matchColor, const Scalar& singlePointColor, const vector &matchesMask, int flags) -
Alex,感谢您提示
drawMatches,它在其他一些情况下对我有用。但是我试过了,结果是一样的,因为这个函数也尝试用 line 函数绘制全长的长线,这在我的情况下不起作用。