コード例 #1
0
        public override bool run()
        {
            try
            {
                method     = (MorphTypes)getValue("method");
                shape      = (MorphShapes)getValue("shape");
                ksize      = (Size)getValue("ksize");
                anchor     = (Point)getValue("anchor");
                iterations = (int)getValue("iterations");
                borderType = (BorderTypes)getValue("borderType");
                Mat element = Cv2.GetStructuringElement(shape, ksize);
                switch (method)
                {
                case MorphTypes.Dilate:
                    dst = src.Dilate(element, anchor, iterations, borderType, null);
                    break;

                case MorphTypes.Erode:
                    dst = src.Erode(element, anchor, iterations, borderType, null);
                    break;

                default:
                    dst = src.MorphologyEx(method, element, anchor, iterations, borderType, null);
                    break;
                }
                TestName = method.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
コード例 #2
0
        public void setMethod(MorphTypes op)
        {
            VP_Morphology Morphology = (VP_Morphology)testcase;

            Morphology.method = op;
            bMethodFreezed    = true;
        }
コード例 #3
0
        //7. 形态学去噪(输入图像为黑白图像)
        public static Mat MorphologicalMethod(Mat inMat, Mat outMat, int a, int b, MorphTypes types)
        {
            Mat x = Cv2.GetStructuringElement(MorphShapes.Ellipse, new Size(a, b));//调整size

            Cv2.MorphologyEx(inMat, outMat, types, x);
            //输入图像、输出图像、types为open时:对图像先腐蚀再膨胀,可以排除小团物体;types为闭运算时(对图像先膨胀再腐蚀,可以排除小型黑洞)
            return(outMat);
        }
コード例 #4
0
 private Mat GetMorph(Mat matS, MorphTypes mtype)
 {
     if (Size % 2 != 1)
     {
         Size++;
     }
     return(matS.MorphologyEx(mtype,
                              Cv2.GetStructuringElement(Shape,
                                                        new Size(Size, Size))));
 }
コード例 #5
0
 public MorphologyLayer(MorphTypes op,
                        int iterations, BorderTypes borderTypes,
                        MorphShapes?morphShapes = null, int?width = null, int?height = null)
 {
     MorphTypes  = op;
     BorderTypes = borderTypes;
     Iterations  = iterations;
     if (morphShapes != null && width != null && height != null)
     {
         Kernel = Cv2.GetStructuringElement(morphShapes.Value, new Size(width.Value,
                                                                        height.Value));
     }
 }
コード例 #6
0
ファイル: TestIp.cs プロジェクト: fengyubox/OpenCVSharpTest
        public static void Morpology(MorphTypes morphTypes = MorphTypes.Erode, MorphShapes shape = MorphShapes.Rect, int kernelSize = 3, int iteration = 1)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);

            var element      = Cv2.GetStructuringElement(shape, new Size(kernelSize, kernelSize));
            var matMorpology = matGray.MorphologyEx(morphTypes, element, iterations: iteration);

            Glb.DrawMatAndHist2(matMorpology);

            matGray.Dispose();
            matMorpology.Dispose();
        }
コード例 #7
0
ファイル: MorphOpenFilter.cs プロジェクト: isigui/HandMotion
 public override void Apply(Mat input)
 {
     _start = DateTime.Now;
     Input  = input;
     if (IsActive)
     {
         Mat        kernel    = Mat.Ones(_morphConfig.KernelSize, _morphConfig.KernelSize);
         MorphTypes morphType = MorphTypes.Open;
         Enum.TryParse(_morphConfig.MorphType, out morphType);
         OpenCvSharp.Cv2.MorphologyEx(Input, Output, morphType, kernel);
     }
     else
     {
         OpenCvSharp.Cv2.CopyTo(input, Output);
     }
     base.Apply(input);
 }
コード例 #8
0
ファイル: TestIp.cs プロジェクト: fengyubox/OpenCVSharpTest
        public static void MorpologyUserKernal(MorphTypes morphTypes = MorphTypes.Erode, int iteration = 1,
                                               byte m00 = 1, byte m01 = 1, byte m02 = 1,
                                               byte m10 = 1, byte m11 = 1, byte m12 = 1,
                                               byte m20 = 1, byte m21 = 1, byte m22 = 1)
        {
            Glb.DrawMatAndHist0(Glb.matSrc);

            var matGray = Glb.matSrc.CvtColor(ColorConversionCodes.BGR2GRAY);

            Glb.DrawMatAndHist1(matGray);
            byte[] arr =
            {
                m00, m01, m02,
                m10, m11, m12,
                m20, m21, m22,
            };
            var element      = new Mat(3, 3, MatType.CV_8UC1, arr);
            var matMorpology = matGray.MorphologyEx(morphTypes, element, iterations: iteration);

            Glb.DrawMatAndHist2(matMorpology);

            matGray.Dispose();
            matMorpology.Dispose();
        }
コード例 #9
0
ファイル: Cv2_imgproc.cs プロジェクト: shimat/opencvsharp
        /// <summary>
        /// 高度なモルフォロジー変換を行います.
        /// </summary>
        /// <param name="src">入力画像</param>
        /// <param name="dst">src と同じサイズ,同じ型の出力画像</param>
        /// <param name="op">モルフォロジー演算の種類</param>
        /// <param name="element">構造要素</param>
        /// <param name="anchor">構造要素内のアンカー位置.デフォルト値の (-1, -1) は,アンカーが構造要素の中心にあることを意味します.</param>
        /// <param name="iterations">収縮と膨張が適用される回数. [既定値は1]</param>
        /// <param name="borderType">ピクセル外挿手法. [既定値はBorderType.Constant]</param>
        /// <param name="borderValue">定数境界モードで利用されるピクセル値.デフォルト値は特別な意味を持ちます. [既定値は CvCpp.MorphologyDefaultBorderValue()]</param>
#else
        /// <summary>
        /// Performs advanced morphological transformations
        /// </summary>
        /// <param name="src">Source image</param>
        /// <param name="dst">Destination image. It will have the same size and the same type as src</param>
        /// <param name="op">Type of morphological operation</param>
        /// <param name="element">Structuring element</param>
        /// <param name="anchor">Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center</param>
        /// <param name="iterations">Number of times erosion and dilation are applied. [By default this is 1]</param>
        /// <param name="borderType">The pixel extrapolation method. [By default this is BorderType.Constant]</param>
        /// <param name="borderValue">The border value in case of a constant border. The default value has a special meaning. [By default this is CvCpp.MorphologyDefaultBorderValue()]</param>
#endif
        public static void MorphologyEx(
            InputArray src, OutputArray dst, MorphTypes op, InputArray element,
            Point? anchor = null, int iterations = 1, 
            BorderTypes borderType = BorderTypes.Constant, Scalar? borderValue = null)
        {
            if (src == null)
                throw new ArgumentNullException(nameof(src));
            if (dst == null)
                throw new ArgumentNullException(nameof(dst));
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            Point anchor0 = anchor.GetValueOrDefault(new Point(-1, -1));
            Scalar borderValue0 = borderValue.GetValueOrDefault(MorphologyDefaultBorderValue());
            IntPtr elementPtr = ToPtr(element);
            NativeMethods.imgproc_morphologyEx(src.CvPtr, dst.CvPtr, (int)op, elementPtr, anchor0, iterations, (int)borderType, borderValue0);
            GC.KeepAlive(src);
            dst.Fix();
        }
コード例 #10
0
ファイル: Mat_CvMethods.cs プロジェクト: CodeSang/opencvsharp
    /// <summary>
    /// 高度なモルフォロジー変換を行います.
    /// </summary>
    /// <param name="op">モルフォロジー演算の種類</param>
    /// <param name="element">構造要素</param>
    /// <param name="anchor">構造要素内のアンカー位置.デフォルト値の (-1, -1) は,アンカーが構造要素の中心にあることを意味します.</param>
    /// <param name="iterations">収縮と膨張が適用される回数. [既定値は1]</param>
    /// <param name="borderType">ピクセル外挿手法. [既定値はBorderTypes.Constant]</param>
    /// <param name="borderValue">定数境界モードで利用されるピクセル値.デフォルト値は特別な意味を持ちます. [既定値は CvCpp.MorphologyDefaultBorderValue()]</param>
    /// <returns>src と同じサイズ,同じ型の出力画像</returns>
#else
        /// <summary>
        /// Performs advanced morphological transformations
        /// </summary>
        /// <param name="op">Type of morphological operation</param>
        /// <param name="element">Structuring element</param>
        /// <param name="anchor">Position of the anchor within the element. The default value (-1, -1) means that the anchor is at the element center</param>
        /// <param name="iterations">Number of times erosion and dilation are applied. [By default this is 1]</param>
        /// <param name="borderType">The pixel extrapolation method. [By default this is BorderTypes.Constant]</param>
        /// <param name="borderValue">The border value in case of a constant border. The default value has a special meaning. [By default this is CvCpp.MorphologyDefaultBorderValue()]</param>
        /// <returns>Destination image. It will have the same size and the same type as src</returns>
#endif
        public Mat MorphologyEx(MorphTypes op, InputArray element,
            Point? anchor = null, int iterations = 1, BorderTypes borderType = BorderTypes.Constant,
            Scalar? borderValue = null)
        {
            var dst = new Mat();
            Cv2.MorphologyEx(this, dst, op, element, anchor, iterations, borderType, borderValue);
            return dst;
        }
コード例 #11
0
 private void Morph(Mat frame, MorphTypes morphTypes)
 {
     frame.MorphologyEx(morphTypes,
                        Cv2.GetStructuringElement(MorphShapes.Ellipse,
                                                  new Size(Size, Size)));
 }
コード例 #12
0
 public static Threshold THRESHOLD(int threst, ThresholdTypes thType, MorphTypes moType)
 => new Threshold(threst, thType, moType);
コード例 #13
0
 public MorphologyConverterImpl(MorphTypes morphTypes = MorphTypes.Erode)
 {
     _morphTypes = morphTypes;
 }