public HObject meanImage(HObject pic) { Application.Current.Dispatcher.Invoke(new Action(() => { ComboBox MeanImageMaskValue = (ComboBox)FindName(CurrentStepGroupBox + "MeanImageMaskValue"); if (MeanImageMaskValue == null) { return; } ComboBoxItem selectedItem = (ComboBoxItem)(MeanImageMaskValue.SelectedValue); int MaskWidth = Convert.ToInt32(selectedItem.Content); int MaskHeight = Convert.ToInt32(selectedItem.Content); Global_ProcessingPic = HD.MeanImage(pic, null, MaskWidth, MaskHeight); HOperatorSet.DispObj(Global_ProcessingPic, ProcessingPic.HalconWindow); })); return(Global_ProcessingPic); }
private void ReadPic_Click(object sender, RoutedEventArgs e) { //for (int i = 0; i < 60; i++) //{ // HOperatorSet.DispCircle(HwindowShow.HalconWindow, i * 10, i * 10, 5); // HOperatorSet.DispCircle(HwindowShow.HalconWindow, i * 10, i * 10, 5); //} HD.closecamera(); background_image = null; HD.clearAllDrawingObject(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "JPEG文件 |*.jpg*|BMP文件|*.bmp*|PNG文件|*.png*"; openFileDialog1.RestoreDirectory = true; openFileDialog1.FilterIndex = 1; //设置对话框属性 if (openFileDialog1.ShowDialog() == true) { ImagePath = openFileDialog1.FileName; background_image = HD.readImage(HwindowShow.HalconWindow, ImagePath); background_image = HD.readImage(OriPicture.HalconWindow, ImagePath); HOperatorSet.DispObj(background_image, OriPicture.HalconWindow); HObject bg_Red, bg_Green, bg_Blue; HObject bg_H, bg_S, bg_V; HOperatorSet.Decompose3(background_image, out bg_Red, out bg_Green, out bg_Blue); HOperatorSet.TransFromRgb(bg_Red, bg_Green, bg_Blue, out bg_H, out bg_S, out bg_V, "hsv"); // HOperatorSet.Rgb1ToGray(background_image, out background_image); if (background_image == null) { return; } if (ReadFilterfc.picturetype == "gray") { HOperatorSet.Rgb1ToGray(background_image, out background_image); } else if (ReadFilterfc.picturetype == "R") { background_image = bg_Red; } else if (ReadFilterfc.picturetype == "G") { background_image = bg_Green; } else if (ReadFilterfc.picturetype == "B") { background_image = bg_Blue; } else if (ReadFilterfc.picturetype == "H") { background_image = bg_H; } else if (ReadFilterfc.picturetype == "S") { background_image = bg_S; } else if (ReadFilterfc.picturetype == "V") { background_image = bg_V; } else { HOperatorSet.Rgb1ToGray(background_image, out background_image); } if (ReadFilterfc.binomialfilterState == true) { HD.BinomialFilter(background_image, HwindowShow.HalconWindow, ReadFilterfc.binomialfiltermaskvalue, ReadFilterfc.binomialfiltermaskvalue); } else if (ReadFilterfc.gaussFilterState == true) { HD.GaussFilter(background_image, HwindowShow.HalconWindow, ReadFilterfc.gaussFiltersize); } else if (ReadFilterfc.meanImageState == true) { HD.MeanImage(background_image, HwindowShow.HalconWindow, ReadFilterfc.meanImagemaskValue, ReadFilterfc.meanImagemaskValue); } else if (ReadFilterfc.sigmaImageState == true) { HD.SigmaImage(background_image, HwindowShow.HalconWindow, ReadFilterfc.sigmaImagemaskValue, ReadFilterfc.sigmaImagemaskValue, ReadFilterfc.sigmaImagesigmaValue); } else if (ReadFilterfc.smoothImageState == true) { HD.SmoothImage(background_image, HwindowShow.HalconWindow, ReadFilterfc.smoothImagefiltertype, ReadFilterfc.smoothImagealpha); } HOperatorSet.DispObj(background_image, HwindowShow.HalconWindow); } else { return; } HwindowShow.HalconWindow.AttachBackgroundToWindow(new HImage(background_image)); display_results_delegate = new DisplayResultsDelegate(() => { lock (image_lock) { if (ho_EdgeAmplitude != null) { HD.display_results(ho_EdgeAmplitude); } HwindowShow.HalconWindow.DispCross(-12.0, -12.0, 3.0, 0); // 在 坐标(-12.0 ,-12.0) 画线宽为3 角度为0 的交叉线 } }); cb = new CallBack(HDrawingObjectCallback); HwindowShow.Focus(); }