private void DisplayResult(CogRecordDisplay Display, CogToolBlock checker) { if (checker.RunStatus.Result != 0) { Display.Image = (checker.Outputs["OutputImage"].Value as Cognex.VisionPro.ICogImage); Display.Fit(false); } else { Cognex.VisionPro.ICogRecord record = checker.CreateLastRunRecord(); Display.Image = (checker.Outputs["OutputImage"].Value as Cognex.VisionPro.ICogImage); Display.Record = record; Display.Fit(false); } }
// If it is called by a worker thread, // InvokeRequired is true, as described above. When this occurs, a delegate is constructed // which is really a pointer to the method that the GUI thread should call. // BeginInvoke is then called, with this delegate and the Image parameter. // Notice that this subroutine tells the GUI thread to call the same subroutine! // When the GUI calls this method on its own thread, InvokeRequired will be false and the // CogRecordDisplay is updated with the info. // This method handles the UserResultAvailable Event. The user packet // has been configured to contain the blob tool input image, which we retrieve and display. private void myJobManager_UserResultAvailable(object sender, CogJobManagerActionEventArgs e) { if (InvokeRequired) { BeginInvoke(new UserResultDelegate(myJobManager_UserResultAvailable), new object[] { sender, e }); return; } Cognex.VisionPro.ICogRecord tmpRecord; Cognex.VisionPro.ICogRecord topRecord = myJobManager.UserResult(); // check to be sure results are available if (topRecord == null) { return; } // Assume that the required "count" record is present, and go get it. tmpRecord = topRecord.SubRecords[@"Tools.Item[""CogBlobTool1""].CogBlobTool.Results.GetBlobs().Count"]; int count = (int)tmpRecord.Content; myCountText.Text = count.ToString(); // Assume that the required "image" record is present, and go get it. tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"]; tmpRecord = tmpRecord.SubRecords["LastRun"]; tmpRecord = tmpRecord.SubRecords["Image Source.OutputImage"]; cogRecordDisplay1.Record = tmpRecord; cogRecordDisplay1.Fit(true); }
private void Window_Loaded(object sender, RoutedEventArgs e) { display.HorizontalScrollBar = false; display.VerticalScrollBar = false; display.Image = new CogImage24PlanarColor(new System.Drawing.Bitmap(@"C:\Users\jkhong\Desktop\이미지 009.bmp")); display.Fit(); }
public bool setImage(Bitmap bitmap) { if (null != cogRecordDisplay) { if (null != bitmap) { if (null != Imagein) { Imagein.Dispose(); } Imagein = new Bitmap(bitmap); cogRecordDisplay.Image = new CogImage8Grey(Imagein); } else { cogRecordDisplay.Image = null; } cogRecordDisplay.Fit(true); return(true); } return(false); }
private bool GetResult1(ref Result1 result) { if (null == myJobManager1) { return false; } ICogRecord tmpRecord; ICogRecord topRecord; try { topRecord = myJobManager1.UserResult(); if (null == topRecord) { return false; } tmpRecord = topRecord.SubRecords[@"Angle"]; if (null != tmpRecord.Content) { result.ResultAngle = (double)tmpRecord.Content; } tmpRecord = topRecord.SubRecords[@"Tilt"]; if (null != tmpRecord.Content) { result.ResultTilt = (double)tmpRecord.Content; } tmpRecord = topRecord.SubRecords[@"Distance"]; if (null != tmpRecord.Content) { result.ResultDistance = (double)tmpRecord.Content; } if (null != cogRecordDisplay1) { tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"]; tmpRecord = tmpRecord.SubRecords["LastRun"]; tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"]; if (null != tmpRecord.Content) { cogRecordDisplay1.Record = tmpRecord; } cogRecordDisplay1.Fit(true); } return true; } catch { return false; } }
private bool GetResult0(ref Result0 result) { if (null == myJobManager0) { return false; } ICogRecord tmpRecord; ICogRecord topRecord; try { topRecord = myJobManager0.UserResult(); if (null == topRecord) { return false; } tmpRecord = topRecord.SubRecords[@"X"]; if (null != tmpRecord.Content) { result.ResultX = (double)tmpRecord.Content; } tmpRecord = topRecord.SubRecords[@"Y"]; if (null != tmpRecord.Content) { result.ResultY = (double)tmpRecord.Content; } tmpRecord = topRecord.SubRecords[@"Angle"]; if (null != tmpRecord.Content) { result.ResultAngle = (double)tmpRecord.Content; } if (null != cogRecordDisplay0) { tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"]; tmpRecord = tmpRecord.SubRecords["LastRun"]; tmpRecord = tmpRecord.SubRecords["CogFixtureTool1.OutputImage"]; if (null != tmpRecord.Content) { cogRecordDisplay0.Record = tmpRecord; } cogRecordDisplay0.Fit(true); } return true; } catch { return false; } }
/// <summary> /// Chạy lần lượt các tool /// </summary> public bool RunJob() { cogAcqFifoEdit.Subject.Run(); cogImageFileTool.Subject.Run(); // PM Align pmAlignToolEdit.Subject.Run(); if (pmAlignToolEdit.Subject.Results?.Count > 0) { cogFixtureTool.Subject.RunParams.UnfixturedFromFixturedTransform = pmAlignToolEdit.Subject.Results[0].GetPose(); } else { return(false); } cogFixtureTool.Subject.Run(); sharpnessToolEdit1.Subject.Run(); sharpnessToolEdit2.Subject.Run(); cogDisplayMain.Fit(); JobDoneNotice?.Invoke(); return(true); }
private bool GetResult2(ref Result2 result) { if (null == myJobManager2) { return false; } ICogRecord tmpRecord; ICogRecord topRecord; try { topRecord = myJobManager2.UserResult(); if (null == topRecord) { return false; } tmpRecord = topRecord.SubRecords[@"QRCode"]; if (null != tmpRecord.Content) { result.ResultQRCode = (string)tmpRecord.Content; } if (null != cogRecordDisplay2) { tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"]; tmpRecord = tmpRecord.SubRecords["LastRun"]; tmpRecord = tmpRecord.SubRecords["CogImageFileTool1.OutputImage"]; if (null != tmpRecord.Content) { cogRecordDisplay2.Record = tmpRecord; } cogRecordDisplay2.Fit(true); } return true; } catch { return false; } }
// This method grabs the blob count from the // Job Manager User Queue and displays it on the GUI. private void UpdateGUI() { Cognex.VisionPro.ICogRecord tmpRecord; Cognex.VisionPro.ICogRecord topRecord = myJobManager.UserResult(); // check to be sure results are available if (topRecord == null) { return; } // Assume that the required "count" record is present, and go get it. tmpRecord = topRecord.SubRecords[@"Tools.Item[""CogBlobTool1""].CogBlobTool.Results.GetBlobs().Count"]; if (tmpRecord != null) { count = (int)tmpRecord.Content; myCountText.Text = count.ToString(); // Assume that the required "image" record is present, and go get it. tmpRecord = topRecord.SubRecords["ShowLastRunRecordForUserQueue"]; if (tmpRecord != null) { tmpRecord = tmpRecord.SubRecords["LastRun"]; if (tmpRecord != null) { tmpRecord = tmpRecord.SubRecords["Image Source.OutputImage"]; if (tmpRecord != null) { cogRecordDisplay1.Record = tmpRecord; cogRecordDisplay1.Fit(true); } } } } }
private void RefreshDisplay() { _recordDisplay.Record = _toolBlock.CreateLastRunRecord().SubRecords["CogIPOneImageTool1.OutputImage"]; _recordDisplay.Fit(); }
private void Process(string path) { foreach (var tool in m_Stream.Tools) { if (tool is ViDi2.IRedTool redTool) { //이미지 프로세스 using (Bitmap bitmap = new Bitmap(path)) { try { //ViDi2.VisionPro.Image image = new ViDi2.VisionPro.Image(new CogImage8Grey(bitmap)); ViDi2.IImage image = new ViDi2.FormsImage(bitmap); ViDi2.ISample sample = m_Stream.Process(image); foreach (var marking in sample.Markings) { if (marking.Value is ViDi2.IRedMarking redMarking) { #region VisionPro CogRecordDisplay에 ViDi검사 결과 변환하여 표시하기 //CogRecord 생성 CogRecord record = new CogRecord(); //record.Content = image.InternalImage; record.Content = image.Bitmap; //ViDi 검사결과를 VisionPro Record로 변환 CogGraphicCollection gc = new CogGraphicCollection(); ViDi2.VisionPro.RedViewRecord redViewRecord = new ViDi2.VisionPro.RedViewRecord(redMarking.Views[0] as ViDi2.IRedView, new ViDi2.VisionPro.Records.DefaultRedToolGraphicCreator()); if (redViewRecord.HasGraphics && redViewRecord.GraphicsVisible) { foreach (ICogRecord icg in redViewRecord.SubRecords) { gc.Add(icg.Content as ICogGraphic); } } record.SubRecords.Add(new CogRecord() { Content = gc, ContentType = typeof(CogGraphicCollection) }); //CogRecordDisplay에 Record 삽입 CogRecordDisplay.Record = record; CogRecordDisplay.Fit(); #endregion #region WPF Image control 에 ViDi 검사결과 표시 ViDi2.IImage overlay = redMarking.OverlayImage(); Bitmap result = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(result)) { graphics.DrawImage(bitmap, 0, 0); graphics.DrawImage(overlay.Bitmap, 0, 0); } using (var memory = new MemoryStream()) { result.Save(memory, ImageFormat.Bmp); memory.Position = 0; var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); BitmapImageSource = bitmapImage; PropertyChangedEvent(nameof(BitmapImageSource)); } #endregion } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }
public void MainTaskThread() { int count = 0; double constX = 0; double constY = 0; while (flag) { CogImage8Grey image = new CogImage8Grey(); image = camControl.CamGrab(); if (image == null) { continue; } blob.InputImage = image; blob.Run(); double xxx = 0; double yyy = 0; if (blob.Results.GetBlobs().Count != 0) { xxx = blob.Results.GetBlobs()[0].CenterOfMassX; yyy = blob.Results.GetBlobs()[0].CenterOfMassY; } CogRecord record = new CogRecord(); record.SubRecords.Add(blob.CreateLastRunRecord().SubRecords[0]); if (count < 10) { constX += xxx; constY += yyy; Dispatcher.Invoke(new Action(() => { MinX_textBox.Text = xxx.ToString(); MaxX_textBox.Text = xxx.ToString(); MinY_textBox.Text = yyy.ToString(); MaxY_textBox.Text = yyy.ToString(); })); } else if (count == 10) { constX = constX / 10; constY = constY / 10; Dispatcher.Invoke(new Action(() => { StdX_textBox.Text = constX.ToString(); StdY_textBox.Text = constY.ToString(); MinX_textBox.Text = xxx.ToString(); MaxX_textBox.Text = xxx.ToString(); MinY_textBox.Text = yyy.ToString(); MaxY_textBox.Text = yyy.ToString(); })); } else if (count % 60 == 0) { var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image.ToBitmap()); bmp8bpp.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SavedImages\Routine_SavedImage-" + DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss") + ".bmp", ImageFormat.Bmp); Dispatcher.Invoke(new Action(() => { double minx = double.Parse(MinX_textBox.Text); double miny = double.Parse(MinY_textBox.Text); double maxx = double.Parse(MaxX_textBox.Text); double maxy = double.Parse(MaxY_textBox.Text); if (xxx < minx) { MinX_textBox.Text = xxx.ToString(); } if (yyy < miny) { MinY_textBox.Text = yyy.ToString(); } if (xxx > maxx) { MaxX_textBox.Text = xxx.ToString(); } if (yyy > maxy) { MaxY_textBox.Text = yyy.ToString(); } })); } else { Dispatcher.Invoke(new Action(() => { if (Math.Abs(constX - xxx) >= 0.5 || Math.Abs(constY - yyy) >= 0.5) { int a = (int.Parse(AbnormalCount_textBox.Text) + 1); AbnormalCount_textBox.Text = a.ToString(); } var bmp8bpp = Grayscale.CommonAlgorithms.BT709.Apply(image.ToBitmap()); bmp8bpp.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\SavedImages\NG_SavedImage-" + DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss") + ".bmp", ImageFormat.Bmp); double minx = double.Parse(MinX_textBox.Text); double miny = double.Parse(MinY_textBox.Text); double maxx = double.Parse(MaxX_textBox.Text); double maxy = double.Parse(MaxY_textBox.Text); if (xxx < minx) { MinX_textBox.Text = xxx.ToString(); } if (yyy < miny) { MinY_textBox.Text = yyy.ToString(); } if (xxx > maxx) { MaxX_textBox.Text = xxx.ToString(); } if (yyy > maxy) { MaxY_textBox.Text = yyy.ToString(); } })); } count++; Dispatcher.Invoke(new Action(() => { TotalCount_textBox.Text = count.ToString(); display.Image = image; display.Record = record; display.Fit(); })); TextWriter tw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\SavedLog.csv", true); tw.WriteLine(count + "," + xxx + "," + yyy + "," + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss")); tw.Close(); Thread.Sleep(900); } }