[OpenCV] 关于drawLineMatches时碰到的问题

最近进行线特征提取匹配时,用到了暴力匹配的方法,相关的函数如下:

BFMatcher bfm(NORM_HAMMING, false);
bfm.knnMatch(ldesc_1, ldesc_2, line_matches, 2);
bfm.match(ldesc_1, ldesc_2, lmatch);

这里knnMatch所需要的line_matches和match所需要的lmatch数据类型不同:

vector<vector<DMatch>> line_matches;
vector<DMatch> lmatch;

这里knnMatch的相关说明可见头文件features2d.hpp

@param queryDescriptors Query set of descriptors.
@param trainDescriptors Train set of descriptors. This set is not added to the train descriptors collection stored in the class object.
@param mask Mask specifying permissible matches between an input query and train matrices of descriptors.
@param matches Matches. Each matches[i] is k or less matches for the same query descriptor.
@param k Count of best matches found per each query descriptor or less if a query descriptor has less than k possible matches in total.
@param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, the matches vector does not contain matches for fully masked-out query descriptors.
These extended variants of DescriptorMatcher::match methods find several best matches for each query descriptor. The matches are returned in the distance increasing order. See DescriptorMatcher::match for the details about query and train descriptors.
*/
    CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors,
                   CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
                   InputArray mask=noArray(), bool compactResult=false ) const;

简言之就是k近邻的候选匹配点;

而drawLineMatches函数所需要的:

/** @brief Draws the found matches of keylines from two images.

@param img1 first image
@param keylines1 keylines extracted from first image
@param img2 second image
@param keylines2 keylines extracted from second image
@param matches1to2 vector of matches
@param outImg output matrix to draw on
@param matchColor drawing color for matches (chosen randomly in case of default value)
@param singleLineColor drawing color for keylines (chosen randomly in case of default value)
@param matchesMask mask to indicate which matches must be drawn
@param flags drawing flags, see DrawLinesMatchesFlags

@note If both *matchColor* and *singleLineColor* are set to their default values, function draws
matched lines and line connecting them with same color
 */
CV_EXPORTS void drawLineMatches( const Mat& img1, const std::vector<KeyLine>& keylines1, const Mat& img2, const std::vector<KeyLine>& keylines2,
                                 const std::vector<DMatch>& matches1to2, Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ),
                                 const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector<char>& matchesMask = std::vector<char>(),
                                 int flags = DrawLinesMatchesFlags::DEFAULT );

是vector<DMatch>所以这里可直接采用match所得结果lmatch;

另外这里的这个函数如果不添加完全参数,省略默认参数不填写的话会报段错误。。。

具体这块的代码可以参考知乎链接:

https://zhuanlan.zhihu.com/p/54126417

这位学者的github也有pl-slam的相关开源代码。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值