public MainWindow() { InitializeComponent(); camList = new List <GigECamInfo>(); grabbers = new CogFrameGrabbers(); if (grabbers.Count != 0) { for (int i = 0; i < grabbers.Count; i++) { ICogFrameGrabber grabber = grabbers[i]; ICogGigEAccess gigEAccess = grabber.OwnedGigEAccess; string vendor = gigEAccess.GetFeature("DeviceVendorName"); camList.Add(new GigECamInfo() { Name = grabber.Name, SerialNumber = grabber.SerialNumber, VendorName = vendor }); } } dataGrid.ItemsSource = camList; display = new CogDisplay(); WFH.Child = display; fifo = grabbers[0].CreateAcqFifo("Generic GigEVision (Mono)", CogAcqFifoPixelFormatConstants.Format8Grey, 0, false); textBlock.Text = grabbers[0].Name; dataGrid.SelectedIndex = 0; }
public ICogAcqFifo ConnectCam(ICogFrameGrabber CurrentCamFG) { ICogAcqFifo CurrentCamFifo = null; string videoFormat = "Generic GigEVision (Mono)"; CurrentCamFifo = CurrentCamFG.CreateAcqFifo(videoFormat, CogAcqFifoPixelFormatConstants.Format8Grey, 0, true); // CogAcqFifo 초기화 return(CurrentCamFifo); }
private void OnChangeVideoFormat(String videoFormat) { if (_frameGrabber != null) { lock (_lockAcqFifo) { _cogAcqFifo = null; _cogAcqFifo = _frameGrabber.CreateAcqFifo(videoFormat, CogAcqFifoPixelFormatConstants.Format8Grey, 0, false); } CorrectDisplayWindows(); } }
private void brightnessUpDown_ValueChanged(object sender, EventArgs e) { myFrameGrabbers = new CogFrameGrabbers(); myFrameGrabber = myFrameGrabbers[0]; myAcqFifo = AcqFifoTool.Operator; myAcqFifo.OwnedBrightnessParams.Brightness = cogAcqTool.Operator.OwnedBrightnessParams.Brightness; brightnessParams = myAcqFifo.OwnedBrightnessParams; if (brightnessParams != null) { brightnessParams.Brightness = Convert.ToDouble(brightnessUpDown.Value); myAcqFifo.OwnedBrightnessParams.Brightness = brightnessParams.Brightness; cogAcqTool.Operator.OwnedBrightnessParams.Brightness = brightnessParams.Brightness; } }
private void InitializeFifo() { const string VIDEO_FORMAT = "Sony XC75 640x480"; ICogAcqROI ROIParams; myFrameGrabbers = new CogFrameGrabbers(); myFrameGrabber = myFrameGrabbers[0]; myAcqFifo = myFrameGrabber.CreateAcqFifo(VIDEO_FORMAT, Cognex.VisionPro.CogAcqFifoPixelFormatConstants.Format8Grey, 0, false); ROIParams = myAcqFifo.OwnedROIParams; if (ROIParams != null) { ROIParams.SetROIXYWidthHeight(10, 20, 300, 200); } }
public Camera(ICogAcqFifo acqFifo) { if (acqFifo == null) { return; } cogAcqFifo = acqFifo; cogROIParams = cogAcqFifo.OwnedROIParams; cogContrast = cogAcqFifo.OwnedContrastParams; cogExposure = cogAcqFifo.OwnedExposureParams; cogBrightness = cogAcqFifo.OwnedBrightnessParams; cogAcqTrigger = cogAcqFifo.OwnedTriggerParams; GrabTime = DateTime.MinValue; }
public ICogImage Grab_Image(ICogAcqFifo CamFifo) { ICogImage GrabImage; try { CamFifo.AcquiredPixelFormat(); int TrigOut; GrabImage = CamFifo.Acquire(out TrigOut) as CogImage8Grey; return(GrabImage); } catch (Exception e) { return(null); } }
public override void InitializeFrameGrabber() { if (_frameGrabber != null) { if (string.IsNullOrEmpty(VideoFormat)) { return; } // Confirm video format lock (_lockAcqFifo) { try { if (_cogAcqFifo != null) { _cogAcqFifo.Flush(); } bool b16FGrey = _frameGrabber.GetSupportsPixelFormat(CogAcqFifoPixelFormatConstants.Format16Grey); bool b32RGB = _frameGrabber.GetSupportsPixelFormat(CogAcqFifoPixelFormatConstants.Format32RGB); bool bFormat3Plane = _frameGrabber.GetSupportsPixelFormat(CogAcqFifoPixelFormatConstants.Format3Plane); bool bFormat565RGB = _frameGrabber.GetSupportsPixelFormat(CogAcqFifoPixelFormatConstants.Format565RGB); _cogAcqFifo = _frameGrabber.CreateAcqFifo(VideoFormat, CogAcqFifoPixelFormatConstants.Format8Grey, 0, false); //_cogAcqFifo.OutputPixelFormat = CogImagePixelFormatConstants.PlanarRGB8; _cogAcqFifo.Prepare(); _cogAcqFifo.Flush(); ICogAcqTrigger mTrigger = _cogAcqFifo.OwnedTriggerParams; if (mTrigger != null && ExternalTrigger) { mTrigger.TriggerModel = CogAcqTriggerModelConstants.Auto; mTrigger.TriggerLowToHigh = false; _cogAcqFifo.Complete += _delCogCompleteHandler; } } catch (Exception ex) { U.LogPopup(ex.Message); } } OnChangedTriggerMode(TriggerMode); } }
int ToolBlockMode; // ToolBlock Edit 창 출력 인덱스 (라디오 버튼으로 제어) public Form1() { InitializeComponent(); // 초기화 =================================================================================== /// Camera Fifo 초기화 for (int i = 0; i < CamCount; i++) { ICogAcqFifo TempFifo = null; CameraList.Add(TempFifo); } // 저장된 값 가져오기 CM.Load_Json(); Init_vpp(); // VisionPro ToolBlock 데이터 로드 //NJH 20.05.23 // Class 객체 로드 //CM.Load_Object<Calibration>("D:\\NewAlign2\\ClassSaveTest.json"); // UI 디스플레이에 출력 cogToolBlockEditV21.Subject = Calib_Cam1.ToolBlock_Calib_CalcPixelSize; // TOolBlock 라디오 버튼 초기화 radio_PX1.Checked = true; ToolBlockMode = 1; // 저장된 Pixel Size 값 화면에 출력 txt_PxSize1.Text = CM.Cam1_PixelSize.ToString("F3"); Calib_Cam1.PixelSize = CM.Cam1_PixelSize; txt_PxSize2.Text = CM.Cam2_PixelSize.ToString("F3"); Calib_Cam2.PixelSize = CM.Cam2_PixelSize; }
private void Image_Timer_Tick(object sender, EventArgs e) { ICogAcqFifo AcqFifo = null; ICogImage cogImage = null; AcqFifo = ParentForm._acqFifo1; if (AcqFifo != null) { // Acquire an image int trigNum; // Cognex.VisionPro.ICogImage image; try { cogImage = AcqFifo.Acquire(out trigNum); } catch (Exception ex) { } ScanDisplay.Image = cogImage; /* * if (CurrentTopLeft.X >= 0 && CurrentTopLeft.Y >= 0 && CurrentTopLeft.X < ScanDisplay.Width && CurrentTopLeft.Y < ScanDisplay.Height && * CurrentBottomRight.X >= 0 && CurrentBottomRight.Y >= 0 && CurrentBottomRight.X < ScanDisplay.Width && CurrentBottomRight.Y < ScanDisplay.Height) * g.DrawRectangle(MyPen, CurrentTopLeft.X, CurrentTopLeft.Y, CurrentBottomRight.X - CurrentTopLeft.X, CurrentBottomRight.Y - CurrentTopLeft.Y); */ Point TPointLT = new Point(); Point TPointRB = new Point(); double dZoom; double dDx = 0; double dDy = 0; double dIx = 0; double dIy = 0; if (ScanDisplay != null) { dDx = ScanDisplay.Width; dDy = ScanDisplay.Height; if (ScanDisplay.Image != null) { dIx = ScanDisplay.Image.Width; dIy = ScanDisplay.Image.Height; } } dZoom = ScanDisplay.Zoom; string strData; string [] strArray; for (int i = 0; i < gridRectList.Rows.Count; i++) { if (gridRectList.Rows[i].Cells[0].Value != null) { strData = gridRectList.Rows[i].Cells[0].Value.ToString(); strArray = (strData + ",,,,,").Split(','); TPointLT.X = int.Parse(strArray[0]); TPointLT.Y = int.Parse(strArray[1]); TPointRB.X = int.Parse(strArray[2]); TPointRB.Y = int.Parse(strArray[3]); if (TPointLT.X >= 0 && TPointLT.Y >= 0 && TPointLT.X < ScanDisplay.Width && TPointLT.Y < ScanDisplay.Height && TPointRB.X >= 0 && TPointRB.Y >= 0 && TPointRB.X < ScanDisplay.Width && TPointRB.Y < ScanDisplay.Height) { g.DrawRectangle(RectPen, TPointLT.X, TPointLT.Y, TPointRB.X - TPointLT.X, TPointRB.Y - TPointLT.Y); } } } // BarcodeScan(); } GC.Collect(); }
/// <summary> /// Camera Constructor /// </summary> public Camera() { cogAcqFifo = null; }
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { fifo = grabbers[dataGrid.SelectedIndex].CreateAcqFifo("Generic GigEVision (Mono)", CogAcqFifoPixelFormatConstants.Format8Grey, 0, false); textBlock.Text = grabbers[dataGrid.SelectedIndex].Name; }
private void contrastUpDown_ValueChanged(object sender, EventArgs e) { myAcqFifo = AcqFifoTool.Operator; contrastParams.Contrast = Convert.ToDouble(contrastUpDown.Value); cogAcqTool.Operator.OwnedContrastParams.Contrast = contrastParams.Contrast; }
public void InitVision() { SettingUp = false; ImageFileTool = CogImageFileEdit1.Subject; ImageFileTool.Ran += ImageFileTool_Ran; //Set reference to CogAcqFifoTool created by Edit Control //The Acq Fifo Edit Control creates its subject when its AutoCreateTool property is True AcqFifoTool = CogAcqFifoEdit1.Subject; AcqFifoTool.Ran += AcqFifoTool_Ran; cogAcqTool = CogAcqFifoEdit1.Subject; cogAcqTool = cogToolBlockEditV21.Subject.Tools["CogAcqFifoTool1"] as CogAcqFifoTool; cogAcqTool.Run(); //Operator will be Nothing if no Frame Grabber is available. Disable the Frame Grabber //option on the "VisionPro Demo" tab if no frame grabber available. if (AcqFifoTool.Operator == null) { optImageAcquisitionOptionFrameGrabber.Enabled = false; } //Initialize the Dialog box for the "Open File" button on the "VisionPro Demo" tab. ImageAcquisitionCommonDialog.Filter = ImageFileTool.Operator.FilterText; ImageAcquisitionCommonDialog.CheckFileExists = true; ImageAcquisitionCommonDialog.ReadOnlyChecked = true; //AutoCreateTool for the PMAlign edit control is False, therefore, we must create //a PMAlign tool and set the subject of the control to reference the new tool. PatMaxTool = new CogPMAlignTool(); PatMaxTool.Changed += PatMaxTool_Changed; CogPMAlignEdit1.Subject = PatMaxTool; //Change the default Train Region to center of a 640x480 image & change the DOFs //so that Skew is not enabled. Note - TrainRegion is of type ICogRegion, therefore, //we must use a CogRectangleAffine reference in order to call CogRectangleAffine //properties. CogRectangleAffine PatMaxTrainRegion = default(CogRectangleAffine); PatMaxTrainRegion = PatMaxTool.Pattern.TrainRegion as CogRectangleAffine; //PatMaxTrainRegion = cogPMAlignTool.Pattern.TrainRegion as CogRectangleAffine; if ((PatMaxTrainRegion != null)) { PatMaxTrainRegion.SetCenterLengthsRotationSkew(320, 240, 100, 100, 0, 0); PatMaxTrainRegion.GraphicDOFEnable = CogRectangleAffineDOFConstants.Position | CogRectangleAffineDOFConstants.Rotation | CogRectangleAffineDOFConstants.Size; } //PatMaxTool.SearchRegion = PatMaxSearchRegion; //PatMaxSearchRegion.SetCenterWidthHeight(320, 240, 640, 480); //PatMaxSearchRegion.GraphicDOFEnable = CogRectangleDOFConstants.Position | CogRectangleDOFConstants.Size; //PatMaxSearchRegion.Interactive = true; numericUpDown1.Value = Convert.ToDecimal(cogPMAlignTool.RunParams.AcceptThreshold); PatMaxTool.RunParams.AcceptThreshold = Convert.ToDouble(numericUpDown1.Value); numericUpDown2.Value = Convert.ToDecimal(cogPMAlignTool.RunParams.ApproximateNumberToFind); PatMaxTool.RunParams.ApproximateNumberToFind = Convert.ToInt32(numericUpDown2.Value); myAcqFifo = AcqFifoTool.Operator; try { myFrameGrabber = cogAcqTool.Operator.FrameGrabber; myAcqFifo = cogAcqTool.Operator; AcqFifoTool.Operator = myAcqFifo; myAcqFifo.OwnedContrastParams.Contrast = cogAcqTool.Operator.OwnedContrastParams.Contrast; myAcqFifo.OwnedBrightnessParams.Brightness = cogAcqTool.Operator.OwnedBrightnessParams.Brightness; brightnessParams = myAcqFifo.OwnedBrightnessParams; contrastParams = myAcqFifo.OwnedContrastParams; } catch (Exception ex) { MessageBox.Show(ex.Message); } if (brightnessParams != null) { brightnessUpDown.Value = Convert.ToDecimal(brightnessParams.Brightness); } if (contrastParams != null) { contrastUpDown.Value = Convert.ToDecimal(contrastParams.Contrast); } try { cogToolBlockEditV21.Subject.Inputs["Image"].Value = cogRecordDisplay1.Image; } catch (Exception ex) { MessageBox.Show("Input image wasn't set"); } }
//初始化函数2 private void initToolEdit() { //JobManagerEdit.Subject = m_JobManager; //一级视觉 CogToolGroup m_ToolGroup_1 = (CogToolGroup)m_Job_1.VisionTool; cogToolGroupEditV21.Subject = m_ToolGroup_1; if (m_ToolGroup_1 == null) { MessageBox.Show("toolgroup1工具读取失败,窗口将自动关闭"); this.Close(); return; } blobTool_1 = (CogBlobTool)m_ToolGroup_1.Tools["CogBlobTool1"]; if (blobTool_1 == null) { MessageBox.Show("blob1工具读取失败,请退出软件"); } pmaTool_1 = (CogPMAlignTool)m_ToolGroup_1.Tools["caliPMATool"]; if (pmaTool_1 == null) { MessageBox.Show("pma1工具读取失败,请退出软件"); } calibTool_1 = (CogCalibNPointToNPointTool)m_ToolGroup_1.Tools["CogCalibNPointToNPointTool1"]; if (calibTool_1 == null) { MessageBox.Show("calib1工具读取失败,请退出软件"); } acqFifoTool_1 = (CogAcqFifoTool)m_ToolGroup_1.Tools["CogAcqFifoTool1"]; if (acqFifoTool_1 == null) { MessageBox.Show("acqfifo1工具读取失败,窗口将自动关闭"); this.Close(); return; } mAcqFifo_1 = acqFifoTool_1.Operator; if (mAcqFifo_1 == null) { MessageBox.Show("macqfifo1为 null,窗口将自动关闭"); this.Close(); return; } mAcqFifo_1.Timeout = 1000; //二级视觉 CogToolGroup m_ToolGroup_2 = (CogToolGroup)m_Job_2.VisionTool; cogToolGroupEditV22.Subject = m_ToolGroup_2; if (m_ToolGroup_2 == null) { MessageBox.Show("toolgroup2工具读取失败,窗口将自动关闭"); this.Close(); return; } blobTool_2 = (CogBlobTool)m_ToolGroup_2.Tools["CogBlobTool1"]; if (blobTool_2 == null) { MessageBox.Show("blob2工具读取失败,请退出软件"); } pmaTool_2 = (CogPMAlignTool)m_ToolGroup_2.Tools["caliPMATool"]; if (pmaTool_2 == null) { MessageBox.Show("pma2工具读取失败,请退出软件"); } calibTool_2 = (CogCalibNPointToNPointTool)m_ToolGroup_2.Tools["CogCalibNPointToNPointTool1"]; if (calibTool_2 == null) { MessageBox.Show("calib2工具读取失败,请退出软件"); } acqFifoTool_2 = (CogAcqFifoTool)m_ToolGroup_2.Tools["CogAcqFifoTool1"]; if (acqFifoTool_2 == null) { MessageBox.Show("acqfifo2工具读取失败,窗口将自动关闭"); this.Close(); return; } mAcqFifo_2 = acqFifoTool_2.Operator; if (mAcqFifo_2 == null) { MessageBox.Show("macqfifo2为 null,窗口将自动关闭"); this.Close(); return; } mAcqFifo_2.Timeout = 1000; ////对比度Test //ICogAcqContrast mContrast = mAcqFifo_2.OwnedContrastParams; //double val = mContrast.Contrast; //Console.WriteLine(val); //三级视觉 CogToolGroup m_ToolGroup_3 = (CogToolGroup)m_Job_3.VisionTool; cogToolGroupEditV23.Subject = m_ToolGroup_3; if (m_ToolGroup_3 == null) { MessageBox.Show("toolgroup3工具读取失败,窗口将自动关闭"); this.Close(); return; } blobTool_3 = (CogBlobTool)m_ToolGroup_3.Tools["CogBlobTool1"]; if (blobTool_3 == null) { MessageBox.Show("blob3工具读取失败,请退出软件"); } pmaTool_3 = (CogPMAlignTool)m_ToolGroup_3.Tools["caliPMATool"]; if (pmaTool_3 == null) { MessageBox.Show("pma3工具读取失败,请退出软件"); } calibTool_3 = (CogCalibNPointToNPointTool)m_ToolGroup_3.Tools["CogCalibNPointToNPointTool1"]; if (calibTool_3 == null) { MessageBox.Show("calib3工具读取失败,请退出软件"); } acqFifoTool_3 = (CogAcqFifoTool)m_ToolGroup_3.Tools["CogAcqFifoTool1"]; if (acqFifoTool_3 == null) { MessageBox.Show("acqfifo3工具读取失败,窗口将自动关闭"); this.Close(); return; } mAcqFifo_3 = acqFifoTool_3.Operator; if (mAcqFifo_3 == null) { MessageBox.Show("macqfifo3为 null,窗口将自动关闭"); this.Close(); return; } mAcqFifo_3.Timeout = 1000; }