• opencv erode


    opencv erode

    void cv::erode( InputArray src, OutputArray dst, InputArray kernel,
                    Point anchor, int iterations,
                    int borderType, const Scalar& borderValue )
    {
        CV_INSTRUMENT_REGION()
    
        morphOp( MORPH_ERODE, src, dst, kernel, anchor, iterations, borderType, borderValue );
    }
    static void morphOp( int op, InputArray _src, OutputArray _dst,
                         InputArray _kernel,
                         Point anchor, int iterations,
                         int borderType, const Scalar& borderValue )
    {
        CV_INSTRUMENT_REGION()
    
        Mat kernel = _kernel.getMat();
        Size ksize = !kernel.empty() ? kernel.size() : Size(3,3);
        anchor = normalizeAnchor(anchor, ksize);
    
        CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && _src.channels() <= 4 &&
                   borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue() &&
                   (op == MORPH_ERODE || op == MORPH_DILATE) &&
                   anchor.x == ksize.width >> 1 && anchor.y == ksize.height >> 1,
                   ocl_morphOp(_src, _dst, kernel, anchor, iterations, op, borderType, borderValue) )
    
        if (iterations == 0 || kernel.rows*kernel.cols == 1)
        {
            _src.copyTo(_dst);
            return;
        }
    
        if (kernel.empty())
        {
            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;
        }
    
        Mat src = _src.getMat();
        _dst.create( src.size(), src.type() );
        Mat dst = _dst.getMat();
    
        Point s_ofs;
        Size s_wsz(src.cols, src.rows);
        Point d_ofs;
        Size d_wsz(dst.cols, dst.rows);
        bool isolated = (borderType&BORDER_ISOLATED)?true:false;
        borderType = (borderType&~BORDER_ISOLATED);
    
        if(!isolated)
        {
            src.locateROI(s_wsz, s_ofs);
            dst.locateROI(d_wsz, d_ofs);
        }
    
        hal::morph(op, src.type(), dst.type(),
                   src.data, src.step,
                   dst.data, dst.step,
                   src.cols, src.rows,
                   s_wsz.width, s_wsz.height, s_ofs.x, s_ofs.y,
                   d_wsz.width, d_wsz.height, d_ofs.x, d_ofs.y,
                   kernel.type(), kernel.data, kernel.step, kernel.cols, kernel.rows, anchor.x, anchor.y,
                   borderType, borderValue.val, iterations,
                   (src.isSubmatrix() && !isolated));
    }

    代码参考:opencv3_4_1opencv-3.4.1modulesimgprocsrcmorph.cpp

    #################################

    QQ 3087438119
  • 相关阅读:
    《人月神话》读后感
    十天冲刺计划(第二次)
    日历表的事件处理和管理(刘静)
    十天冲刺计划
    结组开发项目(TD学生助手)
    电梯调度(二)
    敏捷软件开发方法综述
    对于二维数组求子数组的和的最大值
    电梯调度(一)
    FloatyFish休闲游戏 Beta正式发布
  • 原文地址:https://www.cnblogs.com/herd/p/15437230.html
Copyright © 2020-2023  润新知