//***************************************************************************************** // Conversion //***************************************************************************************** public ICogImage Conv_BitmapToCogImage(Bitmap bitmap) { CogImage24PlanarColor image = new CogImage24PlanarColor(bitmap); ICogImage cog = image; return(cog); }
private void Single_button_Click(object sender, RoutedEventArgs e) { ICogImage image = fifo.Acquire(out int a); display.Image = image; display.Fit(); }
/// <summary> /// Assign the input image /// </summary> /// <param name="cogImage"></param> private void AssignInputImage(object oImage) { if (oImage != null) { try { ICogImage cogImage = oImage as ICogImage; if (cogImage == null) { if (oImage is Bitmap) { // Assume bitmap cogImage = new CogImage24PlanarColor(oImage as Bitmap); } else { return; } } CogToolBlock grabberBuffer = GetGrabberBuffer(); if (grabberBuffer != null) { grabberBuffer.Outputs["OutputBuffer"].Value = cogImage; } } catch (Exception ex) { U.LogPopup(ex, "Error AssignInputImage image to the Cog vpp file"); } } }
private void Btn_LiveStart_Click(object sender, EventArgs e) // Btn Live Start 버튼 { LiveThreadSwitch = 0; LiveThread = new Thread(new ThreadStart(delegate { for (; ;) { /* * if (ImageMode == 0) // 카메라 사용 시 * { * Image_Cam1 = m_VPro_Cam.Grab_Image(CameraList[0]); * Image_Cam2 = m_VPro_Cam.Grab_Image(CameraList[1]); * } * else // 이미지 파일 사용 시 */ { Image_Cam1 = LoadedImage1; Image_Cam2 = LoadedImage2; } cogRecordDisplay1.Image = Image_Cam1; cogRecordDisplay2.Image = Image_Cam2; if (LiveThreadSwitch == 1) { break; } System.Threading.Thread.Sleep(1); } })); LiveThread.Start(); }
public CcdTerminalIn(int ccdId, ICogImage image, string brand, int index = 0) { CcdId = ccdId; InputImage = image; Brand = brand; ImageIndex = index; }
private void AssignImageToTool(ICogTool cogTool, ICogImage image) { Type ty = null; PropertyInfo pi = null; try { ty = cogTool.GetType(); pi = ty.GetProperty("InputImage"); } catch { } if (pi == null) { U.LogPopup("Could not get the Input Image property from tool '{0}'.", cogTool.Name); } else { try { pi.SetValue(cogTool, image, null); } catch (Exception ex) { U.LogPopup(ex, "Could not set Input Image to '{0}'. The type expected is '{1}' and the type we have is '{2}'", cogTool.Name, pi.PropertyType.Name, image.GetType().Name); } } }
public CcdTerminalIn(int ccdId, ICogImage image, int index = 0) { CcdId = ccdId; InputImage = image; ImageIndex = index; // Brand = VisionConfig.Brand; }
private void Init() { m_cogCalibNPointToNPointTool.Calibration.NumPoints = 3; for (int i = 0; i < 3; i++) { m_pcogPointMaker[i] = new CogPointMarker(); m_cogCalibNPointToNPointTool.Calibration.GetRawCalibratedPoint(i, out m_pdRawX[i], out m_pdRawY[i]); m_cogCalibNPointToNPointTool.Calibration.GetUncalibratedPoint(i, out m_pdPixelX[i], out m_pdPixelY[i]); } m_bCalibrated = m_cogCalibNPointToNPointTool.Calibration.Calibrated; m_icogImageCalibration = m_cogCalibNPointToNPointTool.CalibrationImage; m_bSwapY = m_cogCalibNPointToNPointTool.Calibration.SwapCalibratedHandedness; m_dCaibratedOriginX = m_cogCalibNPointToNPointTool.Calibration.CalibratedOriginX; m_dCaibratedOriginY = m_cogCalibNPointToNPointTool.Calibration.CalibratedOriginY; m_dCaibratedRotation = m_cogCalibNPointToNPointTool.Calibration.CalibratedXAxisRotation; m_dOriginX = m_dCaibratedOriginX; m_dOriginY = m_dCaibratedOriginY; m_dRotation = m_dCaibratedRotation; // 2015.04.08 m_cogCalibNPointToNPointTool.Ran += new EventHandler(RanEvent); }
public int ExtractPosData(int Index, ICogImage CalibImage) // Image 에서 Pixel 좌표를 추출 { double ResultX, ResultY; try { ToolBlock_Calib_Extractor.Inputs["InputImage1"].Value = CalibImage; ToolBlock_Calib_Extractor.Run(); ResultX = (double)ToolBlock_Calib_Extractor.Outputs["Pos1_X"].Value; ResultY = (double)ToolBlock_Calib_Extractor.Outputs["Pos1_Y"].Value; List_PixelPos_X.Insert(Index, ResultX); List_PixelPos_Y.Insert(Index, ResultY); return 1; } catch (Exception e) { return 0; } }
/// <summary> /// Manual Triggerring /// </summary> /// <param name="manualLive"></param> /// <returns></returns> public override object Acquire(bool manualLive) { if (_cogAcqFifo == null) { //if (SimFileName !="" && File.Exists(SimFileName)) //{ // return Bitmap.FromFile(SimFileName); //} return(null); } ICogImage cogImage = null; StopLiveAllCameraWindows(); if (ExternalTrigger) { if (!manualLive) { TriggerMode = eTriggerMode.Idle; } _waitForImage.Reset(); FireTrigger(); try { // Wait for response U.BlockOrDoEvents(_waitForImage, 2000); cogImage = _lastCogImage; } catch (Exception ex) { U.LogError(ex, "Image Acquisition error"); } } else { try { System.Threading.Thread.Sleep(1); int ticket = -1; lock (_lockAcqFifo) { ticket = _cogAcqFifo.StartAcquire(); } cogImage = WaitForImage(ticket); } catch (Exception ex) { U.LogError(ex, "Cognex Acquisition Error"); } D.ObjectEventHandler delCallback = GetNextCallback(); if (delCallback != null) { delCallback(cogImage); } } AssignImageToWindows(cogImage); return(cogImage); }
//***************************************************************************************** // Conversion //***************************************************************************************** public void Do_Ptrn(Bitmap bmpSource, Bitmap bmpTemplate) { CogRectangleAffine PatMaxTrainRegion = default(CogRectangleAffine); PatMaxTrainRegion = PatMaxTool.Pattern.TrainRegion as CogRectangleAffine; ICogImage cogInput = this.Conv_BitmapToCog8Grey(bmpSource); ICogImage cogTeach = this.Conv_BitmapToCog8Grey(bmpTemplate); int imageW = bmpSource.Width; int imageH = bmpSource.Height; int teachW = bmpTemplate.Width; int teachH = bmpTemplate.Height; lock (locker) { CogRectangle PatMaxSearchRegion = new CogRectangle(); PatMaxTool.SearchRegion = PatMaxSearchRegion; PatMaxSearchRegion.SetCenterWidthHeight(PARAM_SEARCH_CX, PARAM_SEARCH_CY, PARAM_RC_SEARCH.Width, PARAM_RC_SEARCH.Height); PatMaxSearchRegion.GraphicDOFEnable = CogRectangleDOFConstants.Position | CogRectangleDOFConstants.Size; PatMaxSearchRegion.Interactive = true; if ((PatMaxTrainRegion != null)) { PatMaxTrainRegion.SetCenterLengthsRotationSkew(teachW / 2, teachH / 2, teachW, teachH, 0, 0); PatMaxTrainRegion.GraphicDOFEnable = CogRectangleAffineDOFConstants.Position | CogRectangleAffineDOFConstants.Rotation | CogRectangleAffineDOFConstants.Size; } try { PatMaxTool.Pattern.TrainImage = cogTeach as CogImage8Grey; PatMaxTool.Pattern.TrainAlgorithm = CogPMAlignTrainAlgorithmConstants.PatMax; PatMaxTool.Pattern.TrainMode = CogPMAlignTrainModeConstants.Image; PatMaxTool.Pattern.Train(); } catch (CogSecurityViolationException ex) { MessageBox.Show("Please Check The License Dongle Validity.", "LISENCE ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } PatMaxTool.InputImage = cogInput; PatMaxTool.RunParams.ApproximateNumberToFind = 100; PatMaxTool.RunParams.AcceptThreshold = 0.5; //PatMaxTool.Changed += PatMaxTool_Changed; ptrnResult.removeAll(); PatMaxTool.Run(); } }
private void AddImageQueue(string Name, ICogImage image) { this.IsAddingImage = true; if (this.ImageQueue.Count < 15 | !this.TooFastSafeguard) { this.ImageQueue.Enqueue(image); this.ImageNameQueue.Enqueue(Name); } this.IsAddingImage = false; }
public void RunToolBlock(CogToolBlock toolBlock, ICogImage image, string brand, int index) { toolBlock.Inputs["InputImage"].Value = image; toolBlock.Inputs["Brand"].Value = brand; toolBlock.Inputs["iAcquirePositionIndex"].Value = index; toolBlock.Run(); RunParams.CcdDisplayBlock[CcdId].Post(1); RunParams.CcdCheckBlock[CcdId].Post(0); }
private void btnLoadCalibImage_Click(object sender, EventArgs e) { m_aDisplay.ClearAll(); m_aDisplay.Display.Image = m_aCalibNPointToNPoint.CalibrationImage; m_aDisplay.Display.Fit(true); m_aCalibNPointToNPoint.InputImage = m_aDisplay.GetImage8Grey(); // 2014.12.28 by kdi m_cogImage = m_aCalibNPointToNPoint.InputImage; m_aCalibNPointToNPoint.ShowCalibratedOrigin(m_aDisplay, false); }
//***************************************************************************************** // Image I/O //***************************************************************************************** public ICogImage ImageLoad_From_CogImageFile(string strPath) { // Extention Header Error Included. // it shows some errors from the different types of bitmaps. CogImageFile cogImageFile = new CogImageFile(); cogImageFile.Open(strPath, CogImageFileModeConstants.Read); ICogImage cogImage = cogImageFile[0]; cogImageFile.Close(); return(cogImage); }
private void btnLoadCalibImage_Click(object sender, EventArgs e) { m_aDisplay.ClearAll(); m_aDisplay.Display.Image = m_aCalibCheckerboard.CalibrationImage; m_aDisplay.Display.Fit(true); m_aCalibCheckerboard.InputImage = m_aDisplay.GetImage8Grey(); // 2014.12.28 by kdi m_cogImage = m_aCalibCheckerboard.InputImage; m_aCalibCheckerboard.ShowCalibratedOrigin(m_aDisplay, chkShowUndistort.Checked, false); }
//ABB private void myImgComplete4(object sender, CogCompleteEventArgs e) //定义ABB的相机 { CogToolBlock myToolBlock; CogToolBlock myRunToolblock3; //= myToolBlock.Tools("MyToolBlock3") int numReadyVal = 0; int numPendingVal = 0; bool busyVal = false; CogToolGroup myTG = (CogToolGroup)myJob.VisionTool; myToolBlock = (CogToolBlock)myTG.Tools["AcquireImageAndProcessLeft"]; myRunToolblock3 = (CogToolBlock)myToolBlock.Tools["MyToolBlock3"]; CogAcqInfo info = new CogAcqInfo(); ICogImage CurrentImage = default(ICogImage); // static int numAcqs = 0; try { AcqFifoTool4.Operator.GetFifoState(out numPendingVal, out numReadyVal, out busyVal); if (numReadyVal > 0) { CurrentImage = (ICogImage)(AcqFifoTool4.Operator.CompleteAcquireEx(info)); } else { //Throw New CogAcqAbnormalException("Ready count is not greater than 0.") } myImgComplete4_numAcqs++; // We need to run the garbage collector on occasion to cleanup // images that are no longer being used. if (myImgComplete4_numAcqs > 4) { GC.Collect(); myImgComplete4_numAcqs = 0; } ModuleCard.d1000_out_bit((short)10, (short)1); // Issue another acquisition request if we are in manual trigger mode. if (!ReferenceEquals(CurrentImage, null)) { myRunToolblock3.Inputs["Input2dImage"].Value = CurrentImage; myRunToolblock3.Run(); } // CogRecordDisplay1.Image = CurrentImage } catch (Exception) { } }
public ICogImage GrabCalibrationImage(ADisplay aDisplay) { if (aDisplay.Image != null) { m_cogCalibCheckerboardTool.Calibration.CalibrationImage = aDisplay.Image; m_icogImageCalibration = aDisplay.Image; m_bGrabed = true; } else { m_bGrabed = false; } return(m_icogImageCalibration); }
public void Load_Image_Cam1() // 이미지 시뮬레이션 모드일 때 이미지 로드 { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Grab Image"; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Bitmap LoadedImage = new Bitmap(ofd.FileName); this.LoadedImage1 = new CogImage8Grey(LoadedImage); // 이미지 시뮬 모드에서는 불러온 이미지를 LoadedImage 변수에 저장하여 보유 txt_ImgPath1.Text = ofd.FileName; } }
public AFrmCogMask(ICogImage image, CogImage8Grey mask) { InitializeComponent(); cogImageMaskEditV2.Image = image; if (mask != null) { cogImageMaskEditV2.MaskImage = mask; // 2014.11.21 m_MaskedImage = cogImageMaskEditV2.MaskImage; m_MaskedGraphic = new CogMaskGraphic(); m_MaskedGraphic.Image = m_MaskedImage; } InitLanguage(); }
public static void Run(Bitmap image, int index, out ArrayList data, out ICogImage outimage, out ICogRecord outrecord) { outimage = new CogImage8Grey(image); block.Inputs["InputImage"].Value = outimage; block.Inputs["Index"].Value = index; block.Run(); outrecord = block.CreateLastRunRecord(); if (block.RunStatus.Result == CogToolResultConstants.Accept) { data = (ArrayList)block.Outputs["data"].Value; } else { throw new Exception("Vision Run Fail"); } }
private void SetCogImage(CogDisplay cogDisplay, ICogImage cogImage) { if (cogDisplay.InvokeRequired) { cogDisplay.BeginInvoke(new _delParamCogImage(SetCogImage), new object[] { cogDisplay, cogImage }); return; } try { cogDisplay.Image = cogImage; } catch (Exception ex) { U.LogError(ex, "Unable to set CognexWindow image"); } }
public ICogImage Run(ICogImage cogImage) { InputImage = cogImage; m_bRan = false; m_cogFixtureNPointToNPointTool.Run(); WaitRanEvent(); if (m_cogFixtureNPointToNPointTool.Result == null) { return(InputImage); } else { return(OutputImage); } }
public void GrabImage() { /* * if (ImageMode == 0) // 카메라 사용 시 * { * Image_Cam1 = m_VPro_Cam.Grab_Image(CameraList[0]); * Image_Cam2 = m_VPro_Cam.Grab_Image(CameraList[1]); * } * else // 이미지 파일 사용 시 */ { Image_Cam1 = LoadedImage1; Image_Cam2 = LoadedImage2; } cogRecordDisplay1.Image = Image_Cam1; cogRecordDisplay1.Fit(); cogRecordDisplay2.Image = Image_Cam2; cogRecordDisplay2.Fit(); }
public ATbEdtFixtureNPointToNPoint(int nType, int nPoint, int nToolIndex) { InitializeComponent(); m_aPoint = AVisionProBuild.GetPoint(nType, nPoint); m_nType = nType; m_nPoint = nPoint; m_nToolIndex = nToolIndex; // 2014.10.30 #if (!_USE_BASLER_PYLON && !_USE_IMAGING_CONTROL && !_USE_1Camera) if (m_aPoint.GetToolCount("AcqFifo") > 0) #endif { // 2014.10.30 #if (!_USE_BASLER_PYLON && !_USE_IMAGING_CONTROL && !_USE_1Camera) m_aAcqFifo = m_aPoint.GetTool("AcqFifo", 0) as AAcqFifo; #elif _USE_1Camera m_aAcqFifo = AVisionProBuild.GetAcq(); #endif } // 2016.07.29 if (m_aPoint.GetToolCount("FixtureNPointToNPoint") > m_nToolIndex) { m_aFixtureNPointToNPoint = m_aPoint.GetTool("FixtureNPointToNPoint", m_nToolIndex) as AFixtureNPointToNPoint; } else { m_aFixtureNPointToNPoint = new AFixtureNPointToNPoint(); m_aFixtureNPointToNPoint.Name = AVisionProBuild.MakeName("FixtureNPointToNPoint", DateTime.Now); m_aPoint.Add("FixtureNPointToNPoint", m_aFixtureNPointToNPoint); } cogFixtureNPointToNPointEditV2.Subject = m_aFixtureNPointToNPoint.GetTool(); InitLanguage(); InitializeFixtureNPointToNPoint(); // 2016.04.06 m_cogImage = m_aFixtureNPointToNPoint.InputImage; }
public int Calc_PixelSize(double ActualDist, ICogImage CalibImage) // Image 에서 Pixel Size 를 계산 { try { ToolBlock_Calib_CalcPixelSize.Inputs["InputImage1"].Value = CalibImage; ToolBlock_Calib_CalcPixelSize.Inputs["ActualDist"].Value = ActualDist; ToolBlock_Calib_CalcPixelSize.Run(); this.PixelSize = (double)ToolBlock_Calib_CalcPixelSize.Outputs["PixelSize"].Value; return 1; } catch (Exception e) { return 0; } }
// 2014.03.27 public int Run(ADisplay aDisplay) { m_stResult.dX = 0; m_stResult.dY = 0; m_stResult.dAngle = 0; if (m_cogFindCornerTool != null) { InputImage = aDisplay.Image; // 2015.04.08 m_bRan = false; m_cogFindCornerTool.Run(); // 2015.04.08 WaitRanEvent(); m_stResult.nR = (int)m_cogFindCornerTool.RunStatus.Result; // 2014.08.28 if (m_stResult.nR == 0 && m_cogFindCornerTool.Result.CornerFound == true) { m_stResult.dX = m_cogFindCornerTool.Result.CornerX; m_stResult.dY = m_cogFindCornerTool.Result.CornerY; // 2016.11.10 m_stResult.dAngle = (m_cogFindCornerTool.Result.LineResultsB.GetLine().Rotation - m_cogFindCornerTool.Result.LineResultsA.GetLine().Rotation) * (180 / Math.PI); } else { m_stResult.nR = -2; } } else { m_stResult.nR = -1; } return(m_stResult.nR); }
private void Init() { m_dSizeX = m_cogCalibCheckerboardTool.Calibration.PhysicalTileSizeX; m_dSizeY = m_cogCalibCheckerboardTool.Calibration.PhysicalTileSizeY; m_emComputationMode = m_cogCalibCheckerboardTool.Calibration.ComputationMode; m_emFiducial = m_cogCalibCheckerboardTool.Calibration.FiducialMark; m_bSwapY = m_cogCalibCheckerboardTool.Calibration.SwapCalibratedHandedness; m_bCalibrated = m_cogCalibCheckerboardTool.Calibration.Calibrated; m_icogImageCalibration = m_cogCalibCheckerboardTool.Calibration.CalibrationImage; m_dCaibratedOriginX = m_cogCalibCheckerboardTool.Calibration.CalibratedOriginX; m_dCaibratedOriginY = m_cogCalibCheckerboardTool.Calibration.CalibratedOriginY; m_dCaibratedRotation = m_cogCalibCheckerboardTool.Calibration.CalibratedXAxisRotation; m_dOriginX = m_dCaibratedOriginX; m_dOriginY = m_dCaibratedOriginY; m_dRotation = m_dCaibratedRotation; m_cogCoordinateAxes.DraggingStopped += new CogDraggingStoppedEventHandler(MyCoordinateAxes_DraggingStopped); // 2015.04.08 m_cogCalibCheckerboardTool.Ran += new EventHandler(RanEvent); }
private ICogImage InvertTarget(ICogImage cogImage) { if (cogImage is CogImage24PlanarColor) { CogImage24PlanarColor imgColor = cogImage as CogImage24PlanarColor; if (HasInvertTargetEvent) { ICogImage8PixelMemory memRed, memGreen, memBlue; int width = imgColor.Width; int height = imgColor.Height; int memRowWidth = width + 8; imgColor.Get24PlanarColorPixelMemory(CogImageDataModeConstants.ReadWrite, 0, 0, width, height, out memRed, out memGreen, out memBlue); FireInvertTarget(width, height, memRowWidth, memRed.Scan0, memGreen.Scan0, memBlue.Scan0); memRed.Dispose(); memGreen.Dispose(); memBlue.Dispose(); } cogImage = imgColor; } return(cogImage); }
// 2015.04.01 public int Run(ICogImage cogImage) { // 2016.03.22 m_nFindCount = 0; SetBlobParam(); // 2016.03.29 //if (m_cogBlobTool != null) if (m_cogBlobTool != null && cogImage != null) { m_cogBlobTool.InputImage = CogImageConvert.GetIntensityImage(cogImage, 0, 0, cogImage.Width, cogImage.Height); if (m_cogimgMask != null) { m_cogBlobTool.RunParams.InputImageMask = m_cogimgMask; } try { // 2015.04.08 m_bRan = false; m_cogBlobTool.Run(); // 2015.04.08 WaitRanEvent(); if (m_cogBlobTool.Results != null) { // 2011.05.24 m_nFindCount = m_cogBlobTool.Results.GetBlobs().Count; } } catch { MessageBox.Show("Run Blob Error"); } } return(m_nFindCount); }