opencv3 feature2d 的探索

想研究一下 feature.cpp中的detect()

virtual void cv::Feature2D::detect    (    InputArray     image,
                                                          std::vector< KeyPoint > &     keypoints,
                                                           InputArray     mask = noArray()  )    

 

没有找到定义

在fast.cpp

class FastFeatureDetector_Impl CV_FINAL : public FastFeatureDetector
{
public:
    FastFeatureDetector_Impl( int _threshold, bool _nonmaxSuppression, int _type )
    : threshold(_threshold), nonmaxSuppression(_nonmaxSuppression), type((short)_type)
    {}

    void detect( InputArray _image, std::vector& keypoints, InputArray _mask ) CV_OVERRIDE
    {
        CV_INSTRUMENT_REGION();

        if(_image.empty())
        {
            keypoints.clear();
            return;
        }

        Mat mask = _mask.getMat(), grayImage;
        UMat ugrayImage;
        _InputArray gray = _image;
        if( _image.type() != CV_8U )
        {
            _OutputArray ogray = _image.isUMat() ? _OutputArray(ugrayImage) : _OutputArray(grayImage);
            cvtColor( _image, ogray, COLOR_BGR2GRAY );
            gray = ogray;
        }
        FAST( gray, keypoints, threshold, nonmaxSuppression, type );
        KeyPointsFilter::runByPixelsMask( keypoints, mask );
    }

 可以看到其中先 检测FAST点,然后通过KeyPointsFilter::runByPixelsMask() 实现滤除mask

来到features2d/src/keypoint.cpp 

void KeyPointsFilter::runByPixelsMask( std::vector& keypoints, const Mat& mask )
{
    CV_INSTRUMENT_REGION();

    if( mask.empty() )
        return;

    keypoints.erase(std::remove_if(keypoints.begin(), keypoints.end(), MaskPredicate(mask)), keypoints.end());
}

 

你可能感兴趣的:(知识)