private void hSmartWindowControlWPF1_HInitWindow(object sender, EventArgs e) { // Initialize window // - Read and attach background image // - Initialize display results delegate function // - Initialize callbacks HTuple width, height; hdev_export.hv_ExpDefaultWinHandle = hSmartWindowControlWPF1.HalconID; HOperatorSet.ReadImage(out background_image, "fabrik"); HOperatorSet.GetImageSize(background_image, out width, out height); hSmartWindowControlWPF1.HalconWindow.SetPart(0.0, 0.0, height - 1, width - 1); hSmartWindowControlWPF1.HalconWindow.AttachBackgroundToWindow(new HImage(background_image)); display_results_delegate = new DisplayResultsDelegate(() => { lock (image_lock) { if (ho_EdgeAmplitude != null) { hdev_export.display_results(ho_EdgeAmplitude); } } }); cb = new HDrawingObject.HDrawingObjectCallback(DisplayCallback); }
private void Camera_screenshot_Click(object sender, RoutedEventArgs e) { background_image = HD.closecamera(); if (background_image == null) { MessageBox.Show("先打开摄像头再截图!! "); return; } HOperatorSet.WriteImage(background_image, "jpg", 0, ".\\1.jpg"); 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(); }
/// <summary> /// Handles the Click event of the btnSearch control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> void btnSearch_Click(object sender, RoutedEventArgs e) { Common.Network.Message msg; Dictionary <string, UIElement> .Enumerator en = _boundProperties.GetEnumerator(); Common.CouchDB.Lucene.QueryBuilder qb = new Common.CouchDB.Lucene.QueryBuilder(); string propertyName; DateTime from, to; // TODO : this needs cleaned up while (en.MoveNext()) { if (en.Current.Value.GetType() == typeof(TextBox)) { propertyName = (string)((TextBox)en.Current.Value).Tag; if (((TextBox)en.Current.Value).Text.Trim().Length > 0) { qb.AddText(propertyName, ((TextBox)en.Current.Value).Text.Trim()); } } else if (en.Current.Value.GetType() == typeof(DatePicker)) { propertyName = (string)((DatePicker)en.Current.Value).Tag; propertyName = propertyName.Replace("_from", ""); if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { from = ((DatePicker)en.Current.Value).SelectedDate.Value; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) { throw new InvalidOperationException("A UIElement of type DatePicker was expected."); } else { break; } } if (!((DatePicker)en.Current.Value).SelectedDate.HasValue) { to = DateTime.MaxValue; } else { to = ((DatePicker)en.Current.Value).SelectedDate.Value; } qb.AddDate(propertyName, from, to); } else { from = DateTime.MinValue; while (en.MoveNext()) { if (en.Current.Value.GetType() != typeof(DatePicker)) { throw new InvalidOperationException("A UIElement of type DatePicker was expected."); } else { break; } } // Does to have a selected value? if (((DatePicker)en.Current.Value).SelectedDate.HasValue) { to = DateTime.MaxValue; qb.AddDate(propertyName, from, to); } } } else { throw new Exception("Unsupported UIElement"); } } Common.CouchDB.Lucene.Search search = new Common.CouchDB.Lucene.Search(_couchdb.Server, _couchdb, "search", "by_all", qb); Common.CouchDB.Result result = search.Get <Common.CouchDB.Lucene.SearchResultCollection>( 60000, 60000, Settings.Instance.NetworkBufferSize, Settings.Instance.NetworkBufferSize); List <Guid> versionGuids = new List <Guid>(); List <Common.Postgres.Version> versions = new List <Common.Postgres.Version>(); Common.CouchDB.Lucene.SearchResultCollection newSRC = new Common.CouchDB.Lucene.SearchResultCollection(); DisplayResultsDelegate actDisplayResults = DisplayResults; // Get list of all version guids returned for (int i = 0; i < search.SearchResultCollection.Count; i++) { versionGuids.Add(Guid.Parse(search.SearchResultCollection[i].Id)); } // Get all current versions for resources versions = Common.Postgres.Version.GetCurrentVersionsFromVersionGuids(versionGuids.ToArray()); for (int i = 0; i < versions.Count; i++) { newSRC.Add(search.SearchResultCollection.Get(versions[i].VersionGuid)); } Dispatcher.BeginInvoke(actDisplayResults, dgResults, newSRC); }
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(); }