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);
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();

            Animation animation = InspectedObject as Animation;

            if (animation == null)
            {
                return;
            }

            animationClipField.OnChanged += x =>
            {
                AnimationClip clip = Resources.Load <AnimationClip>(x.UUID);

                animation.DefaultClip = clip;
                MarkAsModified();
                ConfirmModify();
            };

            wrapModeField.OnSelectionChanged += x =>
            {
                animation.WrapMode = (AnimWrapMode)x;
                MarkAsModified();
                ConfirmModify();
            };

            speedField.OnChanged   += x => { animation.Speed = x; MarkAsModified(); };
            speedField.OnConfirmed += ConfirmModify;
            speedField.OnFocusLost += ConfirmModify;

            cullingField.OnChanged        += x => { animation.Cull = x; MarkAsModified(); ConfirmModify(); };
            overrideBoundsField.OnChanged += x => { animation.UseBounds = x; MarkAsModified(); ConfirmModify(); };
            centerField.OnChanged         += x =>
            {
                AABox   bounds = animation.Bounds;
                Vector3 min    = x - bounds.Size * 0.5f;
                Vector3 max    = x + bounds.Size * 0.5f;

                animation.Bounds = new AABox(min, max);
                MarkAsModified();
            };
            centerField.OnConfirmed += ConfirmModify;
            centerField.OnFocusLost += ConfirmModify;

            sizeField.OnChanged += x =>
            {
                AABox   bounds = animation.Bounds;
                Vector3 min    = bounds.Center - x * 0.5f;
                Vector3 max    = bounds.Center + x * 0.5f;

                animation.Bounds = new AABox(min, max);
                MarkAsModified();
            };
            sizeField.OnConfirmed += ConfirmModify;
            sizeField.OnFocusLost += ConfirmModify;

            Layout.AddElement(animationClipField);
            Layout.AddElement(wrapModeField);
            Layout.AddElement(speedField);
            Layout.AddElement(cullingField);
            Layout.AddElement(overrideBoundsField);

            GUILayoutX boundsLayout = Layout.AddLayoutX();

            boundsLayout.AddElement(new GUILabel(new LocEdString("Bounds"), GUIOption.FixedWidth(100)));

            GUILayoutY boundsContent = boundsLayout.AddLayoutY();

            boundsContent.AddElement(centerField);
            boundsContent.AddElement(sizeField);

            // Morph shapes
            Renderable  renderable  = animation.SceneObject.GetComponent <Renderable>();
            MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes;

            if (morphShapes != null)
            {
                GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);

                Layout.AddElement(morphShapesToggle);
                GUILayoutY channelsLayout = Layout.AddLayoutY();

                morphShapesToggle.OnToggled += x =>
                {
                    channelsLayout.Active = x;
                    Persistent.SetBool("Channels_Expanded", x);
                };

                channelsLayout.Active = Persistent.GetBool("Channels_Expanded");

                MorphChannel[] channels = morphShapes.Channels;
                for (int i = 0; i < channels.Length; i++)
                {
                    GUILayoutY channelLayout = channelsLayout.AddLayoutY();

                    GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
                    channelLayout.AddSpace(5);
                    GUILayoutY channelContentLayout = channelLayout.AddLayoutY();

                    string    channelName      = channels[i].Name;
                    GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth());

                    channelTitleLayout.AddSpace(15); // Indent
                    channelTitleLayout.AddElement(channelNameField);
                    channelTitleLayout.AddFlexibleSpace();

                    channelNameField.OnToggled += x =>
                    {
                        channelContentLayout.Active = x;

                        Persistent.SetBool(channelName + "_Expanded", x);
                    };

                    channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");

                    MorphShape[] shapes = channels[i].Shapes;
                    for (int j = 0; j < shapes.Length; j++)
                    {
                        GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
                        channelContentLayout.AddSpace(5);

                        LocString nameString = new LocString("[{0}]. {1}");
                        nameString.SetParameter(0, j.ToString());
                        nameString.SetParameter(1, shapes[j].Name);
                        GUILabel shapeNameField = new GUILabel(shapes[j].Name);

                        LocString weightString = new LocEdString("Weight: {0}");
                        weightString.SetParameter(0, shapes[j].Weight.ToString());
                        GUILabel weightField = new GUILabel(weightString);

                        shapeLayout.AddSpace(30); // Indent
                        shapeLayout.AddElement(shapeNameField);
                        shapeLayout.AddFlexibleSpace();
                        shapeLayout.AddElement(weightField);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Registers a set of rows for all child fields of the provided object.
        /// </summary>
        /// <param name="parent">Parent foldout row to which to append the new elements.</param>
        /// <param name="serializableObject">Type of the object whose fields to display.</param>
        private void AddObjectRows(Element parent, SerializableObject serializableObject)
        {
            List <Element> elements = new List <Element>();

            foreach (var field in serializableObject.Fields)
            {
                if (!field.Flags.HasFlag(SerializableFieldAttributes.Animable))
                {
                    continue;
                }

                string propertyPath = parent.path + "/" + field.Name;

                Element element;
                if (AddPropertyRow(parent, field.Name, propertyPath, field.GetProperty(), out element))
                {
                    elements.Add(element);
                }
            }

            // Handle special fields
            if (serializableObject.Type == typeof(Animation))
            {
                Animation   anim        = serializableObject.Object as Animation;
                MorphShapes morphShapes = anim?.SceneObject.GetComponent <Renderable>()?.Mesh.Value?.MorphShapes;

                if (morphShapes != null)
                {
                    string propertyPath = parent.path + "/MorphShapes";

                    Action <Element, bool> toggleCallback =
                        (toggleParent, expand) =>
                    {
                        toggleParent.childLayout.Clear();
                        toggleParent.children = null;

                        toggleParent.indentLayout.Active = expand;

                        if (expand)
                        {
                            List <Element> childElements = new List <Element>();
                            MorphChannel[] channels      = morphShapes.Channels;
                            for (int i = 0; i < channels.Length; i++)
                            {
                                string channelName = channels[i].Name;

                                string framePropertyPath  = parent.path + "/MorphShapes/Frames/" + channelName;
                                string weightPropertyPath = parent.path + "/MorphShapes/Weight/" + channelName;

                                childElements.Add(AddFieldRow(toggleParent.childLayout, channelName + " (Frames)",
                                                              toggleParent.so, toggleParent.comp, framePropertyPath,
                                                              SerializableProperty.FieldType.Float));

                                childElements.Add(AddFieldRow(toggleParent.childLayout, channelName + " (Weight)",
                                                              toggleParent.so, toggleParent.comp, weightPropertyPath,
                                                              SerializableProperty.FieldType.Float));
                            }

                            toggleParent.children = childElements.ToArray();
                        }
                    };


                    elements.Add(AddFoldoutRow(parent.childLayout, null, "MorphShapes", parent.so, parent.comp,
                                               propertyPath, toggleCallback));
                }
            }

            parent.children = elements.ToArray();
        }
Beispiel #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="shape"></param>
 /// <param name="ksize"></param>
 /// <param name="anchor"></param>
 /// <returns></returns>
 public static Mat GetStructuringElement(MorphShapes shape, Size ksize, Point anchor)
 {
     IntPtr matPtr = NativeMethods.imgproc_getStructuringElement((int)shape, ksize, anchor);
     return new Mat(matPtr);
 }
Beispiel #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="shape"></param>
 /// <param name="ksize"></param>
 /// <returns></returns>
 public static Mat GetStructuringElement(MorphShapes shape, Size ksize)
 {
     return GetStructuringElement(shape, ksize, new Point(-1, -1));
 }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            Animation animation = (Animation)InspectedObject;

            drawer.AddDefault(animation);

            // Morph shapes
            Renderable  renderable  = animation.SceneObject.GetComponent <Renderable>();
            MorphShapes morphShapes = renderable?.Mesh.Value?.MorphShapes;

            if (morphShapes != null)
            {
                GUIToggle morphShapesToggle = new GUIToggle(new LocEdString("Morph shapes"), EditorStyles.Foldout);

                Layout.AddElement(morphShapesToggle);
                GUILayoutY channelsLayout = Layout.AddLayoutY();

                morphShapesToggle.OnToggled += x =>
                {
                    channelsLayout.Active = x;
                    Persistent.SetBool("Channels_Expanded", x);
                };

                channelsLayout.Active = Persistent.GetBool("Channels_Expanded");

                MorphChannel[] channels = morphShapes.Channels;
                for (int i = 0; i < channels.Length; i++)
                {
                    GUILayoutY channelLayout = channelsLayout.AddLayoutY();

                    GUILayoutX channelTitleLayout = channelLayout.AddLayoutX();
                    channelLayout.AddSpace(5);
                    GUILayoutY channelContentLayout = channelLayout.AddLayoutY();

                    string    channelName      = channels[i].Name;
                    GUIToggle channelNameField = new GUIToggle(channelName, EditorStyles.Expand, GUIOption.FlexibleWidth());

                    channelTitleLayout.AddSpace(15); // Indent
                    channelTitleLayout.AddElement(channelNameField);
                    channelTitleLayout.AddFlexibleSpace();

                    channelNameField.OnToggled += x =>
                    {
                        channelContentLayout.Active = x;

                        Persistent.SetBool(channelName + "_Expanded", x);
                    };

                    channelContentLayout.Active = Persistent.GetBool(channelName + "_Expanded");

                    MorphShape[] shapes = channels[i].Shapes;
                    for (int j = 0; j < shapes.Length; j++)
                    {
                        GUILayoutX shapeLayout = channelContentLayout.AddLayoutX();
                        channelContentLayout.AddSpace(5);

                        LocString nameString = new LocString("[{0}]. {1}");
                        nameString.SetParameter(0, j.ToString());
                        nameString.SetParameter(1, shapes[j].Name);
                        GUILabel shapeNameField = new GUILabel(shapes[j].Name);

                        LocString weightString = new LocEdString("Weight: {0}");
                        weightString.SetParameter(0, shapes[j].Weight.ToString());
                        GUILabel weightField = new GUILabel(weightString);

                        shapeLayout.AddSpace(30); // Indent
                        shapeLayout.AddElement(shapeNameField);
                        shapeLayout.AddFlexibleSpace();
                        shapeLayout.AddElement(weightField);
                    }
                }
            }
        }