Example #1
0
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs = new ItemCollection()
            {
                new ItemBase("MinGray", (int)0, "最小灰度(阈值分割)"),
                new ItemBase("MaxGray", (int)120, "最大灰度(阈值分割)"),
                new ItemBase("MorphologicalKernalWidth", (int)20, "形态学运算核宽度"),
                new ItemBase("MorphologicalKernalHeight", (int)50, "形态学运算核高度"),
                new ItemBase("ErosionRectangleWidth", (int)10, "腐蚀矩形宽度"),
                new ItemBase("ErosionRectangleHeight", (int)90, "腐蚀矩形高度"),
            };

            //配置输出参数
            Outputs = new ItemCollection()
            {
                new ItemBase("X", typeof(double), "X坐标"),
                new ItemBase("Y", typeof(double), "Y坐标"),
                new ItemBase("Angle", typeof(double), "角度"),
            };
        }
Example #2
0
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs.Clear();

            //配置输出参数
            Outputs = new ItemCollection()
            {
                new ItemBase("BaseX", typeof(double), "基准点X"),
                new ItemBase("BaseY", typeof(double), "基准点Y"),
                new ItemBase("Angle", typeof(double), "角度(弧度)"),
            };
        }
Example #3
0
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs = new ItemCollection()
            {
                new ItemBase("MinThreshold", 0, typeof(int), "最小阈值"),
                new ItemBase("MaxThreshold", 70, typeof(int), "最大阈值"),
                new ItemBase("BlobArea", 10000, typeof(int), "过滤杂斑面积"),
            };

            //配置输出参数
            Outputs = new ItemCollection()
            {
                new ItemBase("ItemLocation", new Location[0], typeof(Location[]), "物料位置(数组)")
            };
        }
Example #4
0
        private void ConfigSmartWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            configWindow = null;
            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;
        }
Example #5
0
        private void RunningSmartWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            runningWindow = null;
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;
        }
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs = new ItemCollection()
            {
                new ItemBase("HMinThreshold", 60, typeof(int), "H通道最小阈值"),
                new ItemBase("HMaxThreshold", 140, typeof(int), "H通道最大阈值"),
                new ItemBase("SMinThreshold", 0, typeof(int), "S通道最小阈值"),
                new ItemBase("SMaxThreshold", 35, typeof(int), "S通道最大阈值"),
                new ItemBase("IMinThreshold", 90, typeof(int), "I通道最小阈值"),
                new ItemBase("IMaxThreshold", 135, typeof(int), "I通道最大阈值"),

                new ItemBase("OpenRadius", 3.5, typeof(double), "开运算半径"),
                new ItemBase("CloseRadius", 1.0, typeof(double), "闭运算半径"),

                new ItemBase("MinArea", 100000, typeof(int), "最小筛选面积"),
                new ItemBase("MaxArea", 250000, typeof(int), "最大筛选面积"),

                new ItemBase("MinLen1", 600, typeof(int), "最小长边长度"),
                new ItemBase("MaxLen1", 1500, typeof(int), "最小长边长度"),

                new ItemBase("MinLen2", 40, typeof(int), "最小短边长度"),
                new ItemBase("MaxLen2", 200, typeof(int), "最小短边长度"),

                new ItemBase("XLDPhi", 30, typeof(int), "XLD骨骼方向范围(角度)"),

                new ItemBase("AutoSave", true, typeof(bool), "是否自动保存图片"),
                new ItemBase("ImagePath", "image.bmp", typeof(string), "自动保存的图像路径"),
            };

            //配置输出参数
            Outputs = new ItemCollection()
            {
                new ItemBase("ItemLocation", new Location[0], typeof(Location[]), "物料位置(数组)")
            };
        }
Example #7
0
        /// <summary>
        /// 创建VisionOperation新实例
        /// </summary>
        public VisionOperation()
        {
            RunningWindow = new HSmartWindowControlWPF();
            ConfigWindow  = new ConfigWindow();

            Inputs = new ItemCollection
            {
                new ItemBase("Custom", false, "自定义参数")
            };

            Outputs = new ItemCollection
            {
                new ItemBase("ImageWidth", typeof(int), "图像宽度"),
                new ItemBase("ImageHeight", typeof(int), "图像高度"),
                new ItemBase("ImageType", typeof(string), "图像类型"),
                new ItemBase("Custom", typeof(bool), "自定义参数"),
                new ItemBase("Random", typeof(int), "随机数,范围为0-100")
            };
        }
Example #8
0
        public VisionFrame()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;
            ConfigWindow  = runningSmartWindow;

            //var configSmartWindow = new HSmartWindowControlWPF();
            //configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            //configSmartWindow.Unloaded += ConfigSmartWindow_Unloaded;
            //ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs.Clear();

            //配置输出参数
            Outputs.Clear();
        }
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs.Clear();

            //配置输出参数
            Outputs.Clear();
            //Outputs.Add(new ItemBase("ItemCount", 0, typeof(int), "物料数量"));
            Outputs.Add(new ItemBase("ItemLocation", new Location[0], typeof(Location[]), "物料位置(数组)"));
        }
Example #10
0
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            Inputs.Clear();
            Inputs.Add(new ItemBase("ModelPath", @"C:\Users\Public\Documents\MVTec\HALCON-17.12-Progress\examples\hdevelop\Matching\Deformable\brake_disk_bike.dxf", typeof(string), "模板文件(.dxf)路径"));

            //配置输出参数
            Outputs.Clear();
            Outputs.Add(new ItemBase("MatchCount", typeof(int), "匹配数量"));
            Outputs.Add(new ItemBase("Scores", typeof(double[]), "匹配分数(List列表)"));
        }
        public VisionOperation()
        {
            //创建运行时/配置窗口控件
            var runningSmartWindow = new HSmartWindowControlWPF();

            runningSmartWindow.HInitWindow += RunningSmartWindow_HInitWindow;
            runningSmartWindow.Unloaded    += RunningSmartWindow_Unloaded;
            RunningWindow = runningSmartWindow;

            var configSmartWindow = new HSmartWindowControlWPF();

            configSmartWindow.HInitWindow += ConfigSmartWindow_HInitWindow;
            configSmartWindow.Unloaded    += ConfigSmartWindow_Unloaded;
            ConfigWindow = configSmartWindow;

            //配置输入参数
            //配置输入参数
            Inputs = new ItemCollection()
            {
                new ItemBase("CalibrationFile", $"{System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/Calibration.json", typeof(string), "标定文件路径"),

                new ItemBase("MeanImageMaskWidth", 15, typeof(int), "均值滤波掩码宽度"),
                new ItemBase("MeanImageMaskHeight", 15, typeof(int), "均值滤波掩码高度"),
                new ItemBase("DynThresholdOffset", 5.0, typeof(double), "动态阈值偏移量"),

                new ItemBase("Blob1MinArea", 60000, typeof(int), "大圆最小面积"),
                new ItemBase("Blob1MaxArea", 80000, typeof(int), "大圆最大面积"),
                new ItemBase("Blob1MincirCularity", 0.8, typeof(double), "大圆最小圆度"),

                new ItemBase("Blob2MinArea", 20000, typeof(int), "小圆最小面积"),
                new ItemBase("Blob2MaxArea", 35000, typeof(int), "小圆最大面积"),
                new ItemBase("Blob2MincirCularity", 0.8, typeof(double), "小圆最小圆度"),

                new ItemBase("Elements", 30, typeof(int), "圆拟合边缘点数"),
                new ItemBase("DetectHeight", 60, typeof(int), "卡尺工具高度"),
                new ItemBase("DetectWidth", 15, typeof(int), "卡尺工具宽度"),
                new ItemBase("Sigma", 1.0, typeof(double), "高斯滤波因子"),
                new ItemBase("Threshold", 20, typeof(int), "边缘幅度阈值"),
                new ItemBase("Transition", "positive", typeof(string), "过度颜色"),
                new ItemBase("Select", "'max", typeof(string), "有效点位选择"),
                new ItemBase("ActiveNum", 20, typeof(int), "有效点位数"),

                new ItemBase("BaseX", 1.0, typeof(double), "基础点"),
                new ItemBase("BaseY", 1.0, typeof(double), "基础点"),
                new ItemBase("BaseAngle", 1.0, typeof(double), "基础点角度"),
                new ItemBase("LocationX1", 1.0, typeof(double), "点位1X"),
                new ItemBase("LocationY1", 1.0, typeof(double), "点位1Y"),
                new ItemBase("LocationX2", 1.0, typeof(double), "点位2X"),
                new ItemBase("LocationY2", 1.0, typeof(double), "点位2Y"),
                new ItemBase("LocationX3", 1.0, typeof(double), "点位3X"),
                new ItemBase("LocationY3", 1.0, typeof(double), "点位3Y"),
            };

            //配置输出参数
            Outputs = new ItemCollection()
            {
                new ItemBase("BaseX", 1.0, typeof(double), "基础点"),
                new ItemBase("BaseY", 1.0, typeof(double), "基础点"),
                new ItemBase("LocationX1", 1.0, typeof(double), "点位1X"),
                new ItemBase("LocationY1", 1.0, typeof(double), "点位1Y"),
                new ItemBase("LocationX2", 1.0, typeof(double), "点位2X"),
                new ItemBase("LocationY2", 1.0, typeof(double), "点位2Y"),
                new ItemBase("LocationX3", 1.0, typeof(double), "点位3X"),
                new ItemBase("LocationY3", 1.0, typeof(double), "点位3Y"),
            };
        }
Example #12
0
        /// <summary>
        /// Binds a Halcon window to a View Roi Manager.
        /// </summary>
        /// <param name="manager">The View Roi Manager.</param>
        /// <param name="halconWindow">The Halcon window.</param>
        /// <param name="imageBorderName">
        /// The name of the Border Control containing the Halcon window control.
        /// </param>
        /// <param name="loadImageViewModelName">The name of the load image view model to use.</param>
        /// <param name="windowClass">The main window class instance. (Pass "this")</param>
        public static void BindHalconWindow(
            ViewROIManager manager,
            HSmartWindowControlWPF halconWindow,
            string imageBorderName,
            string loadImageViewModelName,
            MainWindow windowClass)
        {
            windowClass.DisposeCollection.Add(windowClass.Events().ContentRendered.Subscribe(_ =>
            {
                // At initialization, the HSmartWindowWPF sometimes shows Width and Height = NaN
                // until reset with second image or a zoom.
                // This code sets them to actual size before the first use.
                halconWindow.Width  = halconWindow.ActualWidth;
                halconWindow.Height = halconWindow.ActualHeight;

                manager.LocHWindowControl = halconWindow;
                manager.LocHWindowControl.HZoomContent = HSmartWindowControlWPF.ZoomContent.Off;

                manager.LocHWindowControl.ContextMenu.ItemsSource = windowClass.MainViewModel.MenuItems;

                // Set the data template.
                manager.LocHWindowControl.ContextMenu.ItemTemplate = windowClass.ContextMenuDataTemplate;

                // Set the ItemsPanelTemplate.
                manager.LocHWindowControl.ContextMenu.ItemsPanel = windowClass.ContextMenuItemsPanelTemplate;

                windowClass.DisposeCollection.Add(Observable.FromEventPattern <HSmartWindowControlWPF.HMouseEventArgsWPF>(manager.LocHWindowControl, "HMouseDoubleClick")
                                                  .Subscribe(a =>
                {
                    manager.ZoomScale = 0;
                    windowClass.comboboxZoom.SelectedIndex =
                        windowClass.comboboxZoom.Items.IndexOf(
                            windowClass.comboboxZoom.Items.OfType <ComboBoxItem>()
                            .FirstOrDefault(x => x.Content.ToString() == "Fit"));
                }));
            }));

            windowClass.DisposeCollection.Add(windowClass.MainViewModel.MenuItems.ItemsAdded
                                              .Where(_ => manager.LocHWindowControl != null)
                                              .Subscribe(
                                                  _ =>
            {
                manager.LocHWindowControl.ContextMenu.ItemsSource = windowClass.MainViewModel.MenuItems;

                // Set the data template.
                manager.LocHWindowControl.ContextMenu.ItemTemplate = windowClass.ContextMenuDataTemplate;

                // Set the ItemsPanelTemplate.
                manager.LocHWindowControl.ContextMenu.ItemsPanel = windowClass.ContextMenuItemsPanelTemplate;
            }));

            windowClass.DisposeCollection.Add(windowClass.Events().LayoutUpdated
                                              .Select(_ => System.Reactive.Unit.Default)
                                              .InvokeCommand(manager.AdjustAspectCommand));

            ParameterExpression targetParameter = LExpression.Parameter(typeof(MainWindow), "x");
            MemberExpression    mainVMExp       = LExpression.Property(targetParameter, "MainViewModel");
            MemberExpression    viewModelExp    = LExpression.Property(mainVMExp, loadImageViewModelName);
            MemberExpression    imageHeightExp  = LExpression.Property(viewModelExp, "ImageHeight");
            MemberExpression    imageWidthExp   = LExpression.Property(viewModelExp, "ImageWidth");
            Expression <Func <MainWindow, int> > imageHeightTargetExp = LExpression.Lambda <Func <MainWindow, int> >(imageHeightExp, new ParameterExpression[] { targetParameter });
            Expression <Func <MainWindow, int> > imageWidthTargetExp  = LExpression.Lambda <Func <MainWindow, int> >(imageWidthExp, new ParameterExpression[] { targetParameter });

            // Using Subscribe here because BindTo sets up a two-way binding which is not wanted.
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(imageHeightTargetExp)
                                              .Subscribe(x => manager.ImageHeight = x));
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(imageWidthTargetExp)
                                              .Subscribe(x => manager.ImageWidth = x));

            MemberExpression borderExp       = LExpression.PropertyOrField(targetParameter, imageBorderName);
            MemberExpression actualHeightExp = LExpression.Property(borderExp, "ActualHeight");
            MemberExpression actualWidthExp  = LExpression.Property(borderExp, "ActualWidth");
            Expression <Func <MainWindow, double> > actualHeightTargetExp = LExpression.Lambda <Func <MainWindow, double> >(actualHeightExp, new ParameterExpression[] { targetParameter });
            Expression <Func <MainWindow, double> > actualWidthTargetExp  = LExpression.Lambda <Func <MainWindow, double> >(actualWidthExp, new ParameterExpression[] { targetParameter });

            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(actualHeightTargetExp)
                                              .Subscribe(x => manager.ContainerHeight = x));
            windowClass.DisposeCollection.Add(windowClass.WhenAnyValue(actualWidthTargetExp)
                                              .Subscribe(x => manager.ContainerWidth = x));
        }