zoukankan      html  css  js  c++  java
  • 【opencv 源码剖析】 三、 morphOp 数学形态学滤波函数, 腐蚀和膨胀就是通过这个函数得到的

    //
    //_kernel : 形态学滤波的核
    //anchor: 锚点再滤波核的位置
    //iterations: 迭代次数
    static void morphOp( int op, InputArray _src, OutputArray _dst,
                         InputArray _kernel,
                         Point anchor, int iterations,
                         int borderType, const Scalar& borderValue )
    {
        Mat src = _src.getMat(), kernel = _kernel.getMat();
        Size ksize = kernel.data ? kernel.size() : Size(3,3);
        anchor = normalizeAnchor(anchor, ksize);
    
        CV_Assert( anchor.inside(Rect(0, 0, ksize.width, ksize.height)) );
    
        _dst.create( src.size(), src.type() );
        Mat dst = _dst.getMat();
    
        if( iterations == 0 || kernel.rows*kernel.cols == 1 )
        {
            src.copyTo(dst);
            return;
        }
    
        if( !kernel.data )
        {
            kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2));
            anchor = Point(iterations, iterations);
            iterations = 1;
        }
        else if( iterations > 1 && countNonZero(kernel) == kernel.rows*kernel.cols )
        {
            anchor = Point(anchor.x*iterations, anchor.y*iterations);
            kernel = getStructuringElement(MORPH_RECT,
                                           Size(ksize.width + (iterations-1)*(ksize.width-1),
                                                ksize.height + (iterations-1)*(ksize.height-1)),
                                           anchor);
            iterations = 1;
        }
    
        int nStripes = 1;
    #if defined HAVE_TBB && defined HAVE_TEGRA_OPTIMIZATION    //这里是TBB指令集操作, 如果你的库没有使用tbb  则这句话不会执行
        if (src.data != dst.data && iterations == 1 &&  //NOTE: threads are not used for inplace processing
            (borderType & BORDER_ISOLATED) == 0 && //TODO: check border types
            src.rows >= 64 ) //NOTE: just heuristics
            nStripes = 4;
    #endif
    
        parallel_for(BlockedRange(0, nStripes),
                     MorphologyRunner(src, dst, nStripes, iterations, op, kernel, anchor, borderType, borderType, borderValue));
    
        //Ptr<FilterEngine> f = createMorphologyFilter(op, src.type(),
        //                                             kernel, anchor, borderType, borderType, borderValue );
    
        //f->apply( src, dst );
        //for( int i = 1; i < iterations; i++ )
        //    f->apply( dst, dst );
    }
    

      

  • 相关阅读:
    arpspoof局域网断网攻击
    2019-2020 SEERC 2019
    2019-2020 XX Open Cup, Grand Prix of Korea
    欧拉函数板子
    Syncthing – 数据同步利器
    程序员的修养 -- 如何写日志(logging)
    css基础
    vim永久设置主题
    基金选择
    如何查看ntp端口是否正常
  • 原文地址:https://www.cnblogs.com/luoyinjie/p/9913884.html
Copyright © 2011-2022 走看看