void Subject_Ran(object sender, EventArgs e) { // This method executes each time the TB runs // Update the CogDisplayRecord with the image and the lastRunRecord cogRecordDisplay1.Image = cogToolBlockEditV21.Subject.Inputs["Image"].Value as CogImage8Grey; CogBlobTool mBlobTool = cogToolBlockEditV21.Subject.Tools["CogBlobTool1"] as CogBlobTool; cogRecordDisplay1.Record = mBlobTool.CreateLastRunRecord(); cogRecordDisplay1.Fit(true); }
private void mToolBlockProcess_Ran(object sender, EventArgs e) { // This method executes each time the TB runs bool result = (bool)(objectManager.mToolBlockProcess.Outputs["InspectionPassed"].Value); if (result) { objectManager.numPass++; } else { objectManager.numFail++; } // Update the label with pass and fail nPass.Text = objectManager.numPass.ToString(); nFail.Text = objectManager.numFail.ToString(); CogBlobTool mBlobTool = objectManager.mToolBlockProcess.Tools["CogBlobTool1"] as CogBlobTool; //get result var blobResult = mBlobTool.Results; var all_blob = blobResult.GetBlobs(); Console.WriteLine($"number blob detected = {all_blob.Count}"); for (int i = 0; i < all_blob.Count; i++) { interfaceManager.SendMessage(Blob_Packet(all_blob[i])); } //var blobRunParam = mBlobTool.RunParams; //Assign picture to display ICogRecord temp = mBlobTool.CreateLastRunRecord(); //temp = temp.SubRecords["BlobImage"]; temp = temp.SubRecords["InputImage"]; cogRecordDisplay1.Record = temp; cogRecordDisplay1.Fit(true); Display(result); Console.WriteLine("Ran done!, time processing = {0} ms", objectManager.mToolBlockProcess.RunStatus.TotalTime); }
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); } }