protected CogImage8Grey RotateImage(CogImage8Grey img) { CogImage8Grey img1 = null; switch (ImageAngle) { case ImageAngle.角度0: img1 = img.Copy(); break; case ImageAngle.角度90: img1 = img.Copy(); //RotateImage((double)90, "constant");img. break; case ImageAngle.角度180: img1 = img.Copy(); //.RotateImage((double)180, "constant"); break; case ImageAngle.角度270: img1 = img.Copy(); //.RotateImage((double)270, "constant"); break; default: break; } return(img1); }
public Calibration() { /* <NOTE> * Class 객체 생성 시 기본적으로 Calibration 에 사용하게 될 ToolBlock 초기화 * Input 터미널 1개를 생성하는 이유는 GUI 에서 ToolBlock 을 수정하게 하기 위함 */ Bitmap TempBMP = new Bitmap(100, 100); ICogImage TempIMage = new CogImage8Grey(TempBMP); string TName = "InputImage1"; ToolBlock_Calib_CalcPixelSize = new CogToolBlock(); // 프로그램 내에서 사용 될 CogToolBlock 객체 (new 필수) CogToolBlockTerminal InputImage_CalcPixel = new CogToolBlockTerminal(TName, TempIMage.GetType()); ToolBlock_Calib_CalcPixelSize.Inputs.Add(InputImage_CalcPixel); ToolBlock_Calib_Extractor = new CogToolBlock(); // 프로그램 내에서 사용 될 CogToolBlock 객체 (new 필수) CogToolBlockTerminal InputImage_Extractor = new CogToolBlockTerminal(TName, TempIMage.GetType()); ToolBlock_Calib_Extractor.Inputs.Add(InputImage_Extractor); ToolBlock_Calib_CalcCalibration = new CogToolBlock(); // 프로그램 내에서 사용 될 CogToolBlock 객체 (new 필수) CogToolBlockTerminal InputImage_CalcCalibration = new CogToolBlockTerminal(TName, TempIMage.GetType()); ToolBlock_Calib_CalcCalibration.Inputs.Add(InputImage_CalcCalibration); // n 회에 대한 좌표 보관하기 위한 List 초기화 InitCalibData(); }
/// <summary> /// Manual Grab Image /// </summary> public bool GrabWait() { bool Status = true; int trigNum, completeTicket; if (cogAcqFifo != null) { if (this.cogAcqTrigger != null) { // Acquire an image try { grabImage = this.cogAcqFifo.CompleteAcquire(this.acqTicket, out completeTicket, out trigNum) as CogImage8Grey; this.numGCAcqs++; // do GC every COGFRAMENUM if (this.numGCAcqs >= 4) { GC.Collect(); this.numGCAcqs = 0; } } catch (Exception ex) { MessageBox.Show("cogAcqFifo Acquire error: " + ex.Message); Status = false; } } } else { Status = false; } return(Status); }
private void ContinueRun() { while (isContinueRun) { try { ICogImage outimage = new CogImage8Grey(); ICogRecord record; ArrayList data = new ArrayList(); Bitmap image; image = ProgramOperation.ALT(MainHwnd); if (image == null) { return; } Vision.Run(image, 1, out data, out outimage, out record); cogRecordDisplay1.Image = outimage; cogRecordDisplay1.Record = record; this.Invoke(updatemethod, data); image.Dispose(); Thread.Sleep(500); Application.DoEvents(); } catch { } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : Run //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override bool HLRun(System.Drawing.Bitmap bipmapImage, out CResultData objResultData) { objResultData = new CResultData(); bool bReturn = false; do { try { m_objImageProcess.InputImage = new CogImage8Grey(bipmapImage); m_objImageProcess.Run(); CogImage8Grey objResultImage = ( CogImage8Grey )m_objImageProcess.OutputImage; objResultData.bitmapResultImage = objResultImage.ToBitmap(); } catch (System.Exception ex) { Trace.Write(ex.Message + "-> " + ex.StackTrace); MakeErrorMessage("HLRun", 5505, ex.Message); break; } bReturn = true; } while(false); objResultData.bitmapInputImage = null;//bipmapImage; objResultData.bResult = bReturn; objResultData.eLibrary = CResultData.enumLibrary.IMAGEPROCESS; m_objResultData = ( CResultData )objResultData.Clone(); return(bReturn); }
private void ButtonOpenFile_Click(object sender, EventArgs e) { string imageFilename; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = false; if (openFileDialog1.ShowDialog() == DialogResult.OK) { imageFilename = openFileDialog1.FileName; Bitmap bitmap = new Bitmap(imageFilename); img = new CogImage8Grey(bitmap); if (this.cogtoolblock != null && this.cogtoolblock.Inputs.Contains("InputImage")) { this.cogtoolblock.Inputs["InputImage"].Value = img; cogToolBlockEditV21.Subject = cogtoolblock; cogToolBlockEditV21.Subject.Run(); } } }
/// <summary> /// Convert the image to Gray scale /// </summary> /// <param name="oImage"></param> /// <returns></returns> public static Bitmap CogImageToGrayBitmap(object oImage) { // Put in Gray format CogImage8Grey greyImage = null; if (oImage != null) { if (oImage is ICogImage) { if (oImage is CogImage8Grey) { greyImage = oImage as CogImage8Grey; } else { } } else { greyImage = new CogImage8Grey(oImage as Bitmap); } } // Put in ICognex 24 color return(greyImage.ToBitmap()); }
public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = false) { objResultData = new CResultData(); bool bReturn = false; do { try { m_objFixtureTool.InputImage = objCogImage; // 여기에 패턴에서 찾은 좌표를 넣어야하는데.. m_objFixtureTool.Run(); CogImage8Grey objResultImage = ( CogImage8Grey )m_objFixtureTool.OutputImage; if (null == objResultImage) { objResultData.objCogImage = objCogImage; break; } else { objResultData.objCogImage = objResultImage; } } catch (System.Exception ex) { Trace.Write(ex.Message + "-> " + ex.StackTrace); break; } bReturn = true; } while(false); objResultData.bResult = bReturn; m_objResultData = ( CResultData )objResultData.Clone(); return(bReturn); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : Run //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override bool HLRun(Cognex.VisionPro.CogImage8Grey objCogImage, out HLDevice.Abstract.CVisionLibraryAbstract.CResultData objResultData, bool bUseCalibrationImage = true) { objResultData = new CResultData(); bool bReturn = false; do { try { m_objImageProcess.InputImage = objCogImage; m_objImageProcess.Run(); CogImage8Grey objResultImage = ( CogImage8Grey )m_objImageProcess.OutputImage; objResultData.objCogImage = objResultImage; } catch (System.Exception ex) { Trace.Write(ex.Message + "-> " + ex.StackTrace); MakeErrorMessage("HLRun", 5505, ex.Message); break; } bReturn = true; } while(false); objResultData.bitmapInputImage = null;//objCogImage.ToBitmap(); objResultData.bResult = bReturn; objResultData.eLibrary = CResultData.enumLibrary.IMAGEPROCESS; m_objResultData = ( CResultData )objResultData.Clone(); return(bReturn); }
private bool Inspection(CogImage8Grey _SrcImage, CogRectangle _InspArea, bool _IsRotate = false) { bool _Result = true; try { if (true == _IsRotate) { CogRectangleAffine _Area = new CogRectangleAffine(); _Area.SetCenterLengthsRotationSkew(_InspArea.CenterX, _InspArea.CenterY, _InspArea.Width, _InspArea.Height, -3.14, 0); IDResults = IDProc.Execute(_SrcImage, _Area); } else { IDResults = IDProc.Execute(_SrcImage, _InspArea); } } catch (Exception ex) { CLogManager.AddSystemLog(CLogManager.LOG_TYPE.ERR, "InspectionID - Inspection Exception : " + ex.ToString(), CLogManager.LOG_LEVEL.LOW); _Result = false; } return(_Result); }
public ICogImage Conv_ByteToCog8Grey(byte[] imageData, int width, int height) { // no padding etc. so size calculation // is simple. var rawSize = width * height; var buf = new SafeMalloc(rawSize); // Copy from the byte array into the // previously allocated. memory Marshal.Copy(imageData, 0, buf, rawSize); // Create Cognex Root thing. var cogRoot = new CogImage8Root(); // Initialise the image root, the stride is the // same as the widthas the input image is byte alligned and // has no padding etc. cogRoot.Initialize(width, height, buf, width, buf); // Create cognex 8 bit image. var cogImage = new CogImage8Grey(); // And set the image roor cogImage.SetRoot(cogRoot); return(cogImage); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //추가 : //목적 : 생성자 //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public CDialogCogPMAlignImageMask(CogImage8Grey objCogImage, CogImage8Grey objCogImageMask) { this.DialogResult = DialogResult.No; m_objCogImageInput = objCogImage; m_objCogImageMask = objCogImageMask; InitializeComponent(); }
public bool GetPatternReference(CogImage8Grey _SrcImage, CogRectangle _Region, double _OriginX, double _OriginY, ref CogPMAlignPattern _Pattern) { //CogPMAlignPattern _Pattern = new CogPMAlignPattern(); _Pattern = new CogPMAlignPattern(); CogRectangleAffine _ReferRegionAffine = new CogRectangleAffine(); _ReferRegionAffine.SetCenterLengthsRotationSkew(_Region.CenterX, _Region.CenterY, _Region.Width, _Region.Height, 0, 0); CogAffineTransformTool _AffineTool = new CogAffineTransformTool(); _AffineTool.InputImage = _SrcImage; _AffineTool.Region = _ReferRegionAffine; _AffineTool.Run(); _Pattern.TrainImage = (CogImage8Grey)_AffineTool.OutputImage; _Pattern.TrainRegion = _ReferRegionAffine; _Pattern.Origin.TranslationX = _OriginX; _Pattern.Origin.TranslationY = _OriginY; try { _Pattern.Train(); } catch { return(false); } return(true); }
private void RunTool(int imagePathSn) { if (testImagePathList.Count > imagePathSn) { CogImage8Grey img = new CogImage8Grey(new Bitmap(testImagePathList[imagePathSn])); //var imgFile = new CogImageFileTool(); //imgFile.Operator.Open(testImagePathList[imagePathSn], CogImageFileModeConstants.Read); //imgFile.Run(); //ICogImage img = imgFile.OutputImage; if (_enableCheckerboard) { _cogCalibCheckerboard.InputImage = img; _cogCalibCheckerboard.Run(); img = (CogImage8Grey)_cogCalibCheckerboard.OutputImage; } _cogToolBlock.Inputs[1].Value = img; if (_enableCalibNPointToNPoint) { _cogCalibNPointToNPoint.InputImage = img; _cogCalibNPointToNPoint.Run(); img = (CogImage8Grey)_cogCalibNPointToNPoint.OutputImage; } _cogToolBlock.Inputs[0].Value = img; _cogToolBlock.Run(); _imageSelectCount = imagePathSn + 1; RefreshImageCount(); } else { MessageBox.Show(@"找不到指定图片"); } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //추가 : //목적 : 마스크 이미지 저장 //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void BtnSave_Click(object sender, EventArgs e) { var pDocument = CDocument.GetDocument; m_objCogImageMask = cogImageMaskEdit.MaskImage; // 저장이 완료되었습니다. pDocument.SetMessage(CDefine.enumAlarmType.ALARM_INFORMATION, 10014); this.DialogResult = DialogResult.OK; CDialogCogPMAlignImageMask.ActiveForm.Close(); }
private void Init() { m_icogRegion = m_cogBlobTool.Region; m_cogimgMask = m_cogBlobTool.RunParams.InputImageMask; m_nThreshold = m_cogBlobTool.RunParams.SegmentationParams.HardFixedThreshold; m_emPolarity = m_cogBlobTool.RunParams.SegmentationParams.Polarity; m_nMinArea = m_cogBlobTool.RunParams.ConnectivityMinPixels; // 2015.04.08 m_cogBlobTool.Ran += new EventHandler(RanEvent); }
private void btnLoadTrainFiles_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); string dataPath = ""; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { dataPath = folderBrowserDialog1.SelectedPath + @"\"; } if (dataPath == "") { return; } _trainRegion = null; DirectoryInfo fileFold = new DirectoryInfo(dataPath); FileInfo[] files = fileFold.GetFiles(); for (int i = 0; files != null && i < files.Length; i++) { try { if (files[i].Extension == ".bmp") { var bitmap = Bitmap.FromFile(files[i].FullName) as Bitmap; _inputImageTrain = bitmap; ICogImage displayImage; if (bitmap != null) { displayImage = new CogImage8Grey(bitmap); } else { displayImage = null; } this.cogDisplayTrain.Image = displayImage; this.cogDisplayTrain.AutoFit = true; } else if (files[i].Extension == ".train") { byte[] content = FileDecoding(files[i].FullName); var loadedPattern = BinaryDeserialize(content) as CogPMAlignPattern; _PMAlignTool.Pattern = loadedPattern; ICogTransform2D transform = loadedPattern.TrainImage.GetTransform(".", loadedPattern.TrainRegion.SelectedSpaceName); ICogShape cogShape = loadedPattern.TrainRegion.Map(transform, CogCopyShapeConstants.GeometryOnly); _trainRegion = cogShape.EnclosingRectangle(CogCopyShapeConstants.GeometryOnly); InitialTrainRegion(); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } } }
public bool FiducialToolBlock(CogImage8Grey Image, out double offset_x, out double offset_y, out double offset_theta) { offset_x = 0; offset_y = 0; offset_theta = 0; bool runStatus = true; String colResult; int i; if (this.cogToolRun != null) { this.cogToolRun.Inputs["InputImage"].Value = Image as CogImage8Grey; this.cogToolRun.Inputs["ImageDirectoryPath"].Value = imagedirectorypath; this.cogToolRun.Inputs["SaveDefectImages"].Value = savedefectimages; this.cogToolRun.Inputs["SaveAllImages"].Value = saveallimages; this.cogToolRun.Run(); ICogRunStatus cogStatus = this.cogToolRun.RunStatus; if (cogStatus.Result == CogToolResultConstants.Error) { runStatus = false; } else { try { offset_x = (double)this.cogToolRun.Outputs["Tool1XOffset"].Value; offset_y = (double)this.cogToolRun.Outputs["Tool1YOffset"].Value; offset_theta = (double)this.cogToolRun.Outputs["Tool1XDegree"].Value; Log.Info(this, "Fiducial offset values,{0},{1},{2}", offset_x, offset_y, offset_theta); } catch { offset_x = 0; offset_y = 0; offset_theta = 0; } } // Need to save images if (savedefectimages || saveallimages) { _imagefilename = this.cogToolRun.Outputs["ImageFileName"].Value.ToString(); } } else { runStatus = false; } return(runStatus); }
public double GetHistogramStandardDeviatioValue(CogImage8Grey _SrcImage, CogRectangle _InspRegion) { CogHistogramTool _CogHistoTool = new CogHistogramTool(); _CogHistoTool.InputImage = _SrcImage; _CogHistoTool.Region = _InspRegion; _CogHistoTool.Run(); double _HistoDeviation = _CogHistoTool.Result.StandardDeviation; return(_HistoDeviation); }
/// <summary> /// Display control 이미지 추가 /// </summary> /// <param name="_cogDisplayImage">Display 할 이미지</param> public void SetDisplayImage(CogImage8Grey _cogDisplayImage) { try { SetDisplayInvoke(kCogDisplay, _cogDisplayImage); } catch { CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "SetDisplayImage(CogImage8Grey) Exception!!", CLogManager.LOG_LEVEL.LOW); } }
public bool Run(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogBlobAlgo _CogBlobAlgo, ref CogBlobResult _CogBlobResult, int _NgNumber = 0) { bool _Result = true; SetHardFixedThreshold(_CogBlobAlgo.ThresholdMin); SetConnectivityMinimum((int)_CogBlobAlgo.BlobAreaMin); SetPolarity(Convert.ToBoolean(_CogBlobAlgo.ForeGround)); //SetMeasurement(CogBlobMeasureConstants.Area, CogBlobMeasureModeConstants.Filter, CogBlobFilterModeConstants.IncludeBlobsInRange, _CogBlobReferAlgo.BlobAreaMin, _CogBlobReferAlgo.BlobAreaMax); return(_Result); }
private bool Inspection(CogImage8Grey _SrcImage, CogRectangle _Region, CogPMAlignPattern _Pattern) { bool _Result = false; HistogramResult = HistogramProc.Execute(_SrcImage, _Region); //HistogramResult.Mean; OneImageProc.InputImage = _SrcImage; //OneImageProc.Operators.Add() return(_Result); }
private void Init() { m_icogImgMask = m_cogHistogramTool.RunParams.InputImageMask; m_icogRegion = m_cogHistogramTool.Region; m_nNumBins = m_cogHistogramTool.RunParams.NumBins; // 2014.09.02 SetInitSearchRegion(); // 2015.04.08 m_cogHistogramTool.Ran += new EventHandler(RanEvent); }
private void btnApply_Click(object sender, EventArgs e) { // 2014.11.21 if (m_MaskedGraphic == null) { m_MaskedGraphic = new CogMaskGraphic(); } m_MaskedImage = cogImageMaskEditV2.MaskImage; m_MaskedGraphic.Image = m_MaskedImage; m_IsApplied = true; this.Close(); }
public VisionRoi(int ccdId) { CcdId = ccdId; BrandId = DbHelper.GetRunStatus("BrandId"); ImageIndex = 0; var db = DbScheme.Connections["Main"]; Roi = db.Query <CcdRoi>("select * from CcdRoi where ccdId = ? and brandId = ? and imageIndex = ?", CcdId, BrandId, ImageIndex).First(); MyCogCopyRegionTool = new CogCopyRegionTool(); DestinationImage = new CogImage8Grey(Roi.Width, Roi.Height); MyCogCopyRegionTool.Region = new CogRectangleAffine(); }
private void btn_openimage_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { CogImageFile imagefile = new CogImageFile(); imagefile.Open(dlg.FileName, CogImageFileModeConstants.Read); m_Image = (CogImage8Grey)imagefile[0]; cogRecordDisplay1.Image = imagefile[0]; cogRecordDisplay1.Fit(); } }
//LDH, 2108.11.07, Auto Pattern Algo public bool AutoPatternFind(CogImage8Grey _SrcImage, CogRectangle _InspRegion, CogAutoPatternAlgo _CogAutoPatternAlgo, ref CogAutoPatternResult _CogAutoPatternResult) { bool _Result = false; //ㅋ태챠퍼ㅐ젇라ㅓㅣㅏ ㅁ~~~ if (Inspection(_SrcImage, _InspRegion, _CogAutoPatternAlgo.ReferenceInfoList[0].Reference) == false) { return(_Result); } Run(_SrcImage, _InspRegion, _CogAutoPatternAlgo, ref _CogAutoPatternResult); return(_Result); }
private void TestImage_button_Click(object sender, RoutedEventArgs e) { CogImage8Grey image = new CogImage8Grey(); image = camControl.CamGrab(); if (image == null) { MessageBox.Show("이미지 촬영 실패!"); } blob.InputImage = image; blob.Run(); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //추가 : //목적 : 실행 이미지 디스플레이 이미지 변경 //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void UpdateDisplay(CogImage8Grey objImage) { do { // 이미지 확인 if (null == objImage) { break; } // 기존 디스플레이 클리어 cogDisplayRunImage.StaticGraphics.Clear(); cogDisplayRunImage.Image = objImage; } while(false); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //추가 : //목적 : 이미지 검사 //설명 : 4장의 이미지를 PMS통해 합친다. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool SetInspectionBusbar(structureMeasureParameter objParameter) { bool bReturn = false; var pDocument = CDocument.GetDocument; // 에러 로그 string strErrorLog = string.Format("CProcessVisionProcess60 {0} SetInspectionBusbar ", m_iCameraIndex); Stopwatch objStopWatch = new Stopwatch(); objStopWatch.Start(); do { // pDocument.SetUpdateLog( ( CDefine.enumLogType )( ( int )CDefine.enumLogType.LOG_VISION_PROCESS_CAMERA_0 + m_iCameraIndex ), strErrorLog ); try { List <byte[]> objImageByte; List <byte[]> objImageByteSecond; CogImageToByteArr(objParameter.objImage, out objImageByte); CogImageToByteArr(objParameter.objImage, out objImageByteSecond); int iWidth = objParameter.objImageBitmap.Width; int iHeight = objParameter.objImageBitmap.Height; CogImage8Grey objCogImage = new CogImage8Grey(objParameter.objImageBitmap); ICogImage8PixelMemory pmr = objCogImage.Get8GreyPixelMemory(CogImageDataModeConstants.Read, 0, 0, iWidth, iHeight); int iStride = pmr.Stride; iWidth = iStride; Mat objMatImage = new Mat(iHeight, iWidth, MatType.CV_8UC1, objImageByte[0]); Mat objMatImageSecond = new Mat(iHeight, iWidth, MatType.CV_8UC1, objImageByteSecond[0]); //m_objMeasure.SetBusbarParameters( objParameter.iThresh, objParameter.iMaskLen, objParameter.iMeasureInterv, objParameter.iCaliperLen, objParameter.iSkipLenFromCenter ); //DoMeasureWelding( int nWidth, int nHeight, byte* pPMS1, int nLRLowThresh, int nLRContinousLen, int nLRHighThresh, byte* pPMS3, int nTBThresh, int nTBContinousLen ); unsafe { m_objMeasure.DoBusbarMeasureWelding(iWidth, iHeight, objMatImage.DataPointer, objParameter.nLRLowThresh, objParameter.nLRContinousLen, objParameter.nLRHighThresh, objMatImageSecond.DataPointer, objParameter.nTBThresh, objParameter.nTBContinousLen); } } catch (Exception ex) { Trace.WriteLine("CMeasureManager.cs -> SetPMSImage ---" + ex.StackTrace); break; } bReturn = true; } while(false); //CDocument.GetDocument.SetUpdateLog( CDefine.enumLogType.LOG_ETC, "Measure SetInspection TactTime : " + objStopWatch.ElapsedMilliseconds.ToString() ); return(bReturn); }