zoukankan      html  css  js  c++  java
  • opencv morphologyEx

    opencv  morphologyEx

    void cv::morphologyEx( InputArray _src, OutputArray _dst, int op,
                           InputArray _kernel, Point anchor, int iterations,
                           int borderType, const Scalar& borderValue )
    {
        CV_INSTRUMENT_REGION()
    
        Mat kernel = _kernel.getMat();
        if (kernel.empty())
        {
            kernel = getStructuringElement(MORPH_RECT, Size(3,3), Point(1,1));
        }
    #ifdef HAVE_OPENCL
        Size ksize = kernel.size();
        anchor = normalizeAnchor(anchor, ksize);
    
        CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && _src.channels() <= 4 &&
            anchor.x == ksize.width >> 1 && anchor.y == ksize.height >> 1 &&
            borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue(),
            ocl_morphologyEx(_src, _dst, op, kernel, anchor, iterations, borderType, borderValue))
    #endif
    
        Mat src = _src.getMat(), temp;
        _dst.create(src.size(), src.type());
        Mat dst = _dst.getMat();
    
    #if !IPP_DISABLE_MORPH_ADV
        CV_IPP_RUN_FAST(ipp_morphologyEx(op, src, dst, kernel, anchor, iterations, borderType, borderValue));
    #endif
    
        switch( op )
        {
        case MORPH_ERODE:
            erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
            break;
        case MORPH_DILATE:
            dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
            break;
        case MORPH_OPEN:
            erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
            dilate( dst, dst, kernel, anchor, iterations, borderType, borderValue );
            break;
        case MORPH_CLOSE:
            dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
            erode( dst, dst, kernel, anchor, iterations, borderType, borderValue );
            break;
        case MORPH_GRADIENT:
            erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
            dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
            dst -= temp;
            break;
        case MORPH_TOPHAT:
            if( src.data != dst.data )
                temp = dst;
            erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
            dilate( temp, temp, kernel, anchor, iterations, borderType, borderValue );
            dst = src - temp;
            break;
        case MORPH_BLACKHAT:
            if( src.data != dst.data )
                temp = dst;
            dilate( src, temp, kernel, anchor, iterations, borderType, borderValue );
            erode( temp, temp, kernel, anchor, iterations, borderType, borderValue );
            dst = temp - src;
            break;
        case MORPH_HITMISS:
            CV_Assert(src.type() == CV_8UC1);
            if(countNonZero(kernel) <=0)
            {
                src.copyTo(dst);
                break;
            }
            {
                Mat k1, k2, e1, e2;
                k1 = (kernel == 1);
                k2 = (kernel == -1);
    
                if (countNonZero(k1) <= 0)
                    e1 = src;
                else
                    erode(src, e1, k1, anchor, iterations, borderType, borderValue);
    
                Mat src_complement;
                bitwise_not(src, src_complement);
                if (countNonZero(k2) <= 0)
                    e2 = src_complement;
                else
                    erode(src_complement, e2, k2, anchor, iterations, borderType, borderValue);
                dst = e1 & e2;
            }
            break;
        default:
            CV_Error( CV_StsBadArg, "unknown morphological operation" );
        }
    }

    代码参考:opencv3_4_1opencv-3.4.1modulesimgprocsrcmorph.cpp

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

    QQ 3087438119
  • 相关阅读:
    vue多个自定义组件动态显示
    vue弹出多个弹框,并可以拖动弹框
    localStorage和sessionStorage
    Sharepoint ListTemplateId
    SharePoint 上传文档太大 无法上传
    Stream Byte[] 转换
    C#转义字符 单引号 双引号 换行 回车 斜杠
    c#中如何获取本机用户名、MAC地址、IP地址、硬盘ID、CPU序列号、系统名称、物理内存
    SharePoint Content Type ID's
    Visual Studio Tip: Get Public Key Token for a Strong Named Assembly 添加强命名 获取强命名值
  • 原文地址:https://www.cnblogs.com/herd/p/15427264.html
Copyright © 2011-2022 走看看