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(); }
public bool Run(CogImage8Grey _SrcImage, ref CogImage8Grey _DestImage, CogRectangle _InspRegion, CogLineFindAlgo _CogLineFindAlgo, ref CogLineFindResult _CogLineFindResult, int _NgNumber = 0) { bool _Result = true; SetCaliperDirection(_CogLineFindAlgo.CaliperSearchDirection); SetCaliper(_CogLineFindAlgo.CaliperNumber, _CogLineFindAlgo.CaliperSearchLength, _CogLineFindAlgo.CaliperProjectionLength, _CogLineFindAlgo.IgnoreNumber); SetCaliperLine(_CogLineFindAlgo.CaliperLineStartX, _CogLineFindAlgo.CaliperLineStartY, _CogLineFindAlgo.CaliperLineEndX, _CogLineFindAlgo.CaliperLineEndY); if (true == Inspection(_SrcImage)) { GetResult(); } if (FindLineResults != null && (_CogLineFindAlgo.CaliperNumber - _CogLineFindAlgo.IgnoreNumber) < (FindLineResults.NumPointsFound + 5)) { try { _CogLineFindResult.StartX = FindLineResults.GetLineSegment().StartX; _CogLineFindResult.StartY = FindLineResults.GetLineSegment().StartY; _CogLineFindResult.EndX = FindLineResults.GetLineSegment().EndX; _CogLineFindResult.EndY = FindLineResults.GetLineSegment().EndY; _CogLineFindResult.Length = FindLineResults.GetLineSegment().Length; _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; _CogLineFindResult.PointCount = FindLineResults.Count; if (_CogLineFindAlgo.UseAlignment) { CogAffineTransformTool _CogTransForm = new CogAffineTransformTool(); CogRectangleAffine _AffineRegion = new CogRectangleAffine(); _AffineRegion.SetCenterLengthsRotationSkew(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height, _CogLineFindResult.Rotation, 0); _CogTransForm.InputImage = _SrcImage; _CogTransForm.Region = _AffineRegion; _CogTransForm.Run(); CogCopyRegionTool _CopyRegion = new CogCopyRegionTool(); _CopyRegion.InputImage = _CogTransForm.OutputImage; _CopyRegion.DestinationImage = _SrcImage; _CopyRegion.RunParams.ImageAlignmentEnabled = true; _CopyRegion.Region = null; _CopyRegion.Run(); _DestImage = (CogImage8Grey)_CopyRegion.OutputImage; if (true == Inspection(_DestImage)) { GetResult(); } if (FindLineResults != null) { _CogLineFindResult.StartX = FindLineResults.GetLineSegment().StartX; _CogLineFindResult.StartY = FindLineResults.GetLineSegment().StartY; _CogLineFindResult.EndX = FindLineResults.GetLineSegment().EndX; _CogLineFindResult.EndY = FindLineResults.GetLineSegment().EndY; _CogLineFindResult.Length = FindLineResults.GetLineSegment().Length; _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; _CogLineFindResult.PointCount = FindLineResults.Count; _CogLineFindResult.IsGood = true; } else { _CogLineFindResult.IsGood = false; } GC.Collect(); } else { _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; double _Rotation = 0; _Rotation = _CogLineFindResult.Rotation * 180 / Math.PI; _CogLineFindResult.IsGood = true; } } catch { _CogLineFindResult.IsGood = false; } } else { _CogLineFindResult.IsGood = false; } return(_Result); }
public bool Run(CogImage8Grey _SrcImage, ref CogImage8Grey _DestImage, CogRectangle _InspRegion, CogLineFindAlgo _CogLineFindAlgo, ref CogLineFindResult _CogLineFindResult, int _NgNumber = 0) { bool _Result = true; SetCaliperContrastAndHalfPixel(_CogLineFindAlgo.ContrastThreshold, _CogLineFindAlgo.FilterHalfSizePixels); SetCaliperDirection(_CogLineFindAlgo.CaliperSearchDirection); SetCaliper(_CogLineFindAlgo.CaliperNumber, _CogLineFindAlgo.CaliperSearchLength, _CogLineFindAlgo.CaliperProjectionLength, _CogLineFindAlgo.IgnoreNumber); SetCaliperLine(_CogLineFindAlgo.CaliperLineStartX, _CogLineFindAlgo.CaliperLineStartY, _CogLineFindAlgo.CaliperLineEndX, _CogLineFindAlgo.CaliperLineEndY); if (true == Inspection(_SrcImage)) { GetResult(); } if (FindLineResults != null && (_CogLineFindAlgo.CaliperNumber - _CogLineFindAlgo.IgnoreNumber) < (FindLineResults.NumPointsFound + 5)) { try { _CogLineFindResult.StartX = FindLineResults.GetLineSegment().StartX; _CogLineFindResult.StartY = FindLineResults.GetLineSegment().StartY; _CogLineFindResult.EndX = FindLineResults.GetLineSegment().EndX; _CogLineFindResult.EndY = FindLineResults.GetLineSegment().EndY; _CogLineFindResult.Length = FindLineResults.GetLineSegment().Length; _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; _CogLineFindResult.PointCount = FindLineResults.Count; #region Line segment 설정별로, 결과 각도별로 보정값 계산 //Radian 값으로 설정 //Line segment가 가로 //if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -45 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= 45) if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -0.785 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= 0.785) { _CogLineFindResult.LineRotation = FindLineResults.GetLineSegment().Rotation; } //Line segment가 가로 //else if ((FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -180 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= -130) || // (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 135 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 180)) else if ((FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -3.15 && FindLineProc.RunParams.ExpectedLineSegment.Rotation <= -2.26) || (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 2.26 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 3.14)) { if (_CogLineFindResult.Rotation > 0) { _CogLineFindResult.LineRotation = _CogLineFindResult.Rotation - 3.14159; } else { _CogLineFindResult.LineRotation = 3.14159 + _CogLineFindResult.Rotation; } } //Line segment가 세로(90도) else if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= 0.785 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < 2.35) { _CogLineFindResult.LineRotation = (-1.57) + _CogLineFindResult.Rotation; } else if (FindLineProc.RunParams.ExpectedLineSegment.Rotation >= -2.35 && FindLineProc.RunParams.ExpectedLineSegment.Rotation < -0.785) { _CogLineFindResult.LineRotation = _CogLineFindResult.Rotation - (-1.57); } #endregion if (_CogLineFindAlgo.UseAlignment) { CogAffineTransformTool _CogTransForm = new CogAffineTransformTool(); CogRectangleAffine _AffineRegion = new CogRectangleAffine(); _AffineRegion.SetCenterLengthsRotationSkew(_InspRegion.CenterX, _InspRegion.CenterY, _InspRegion.Width, _InspRegion.Height, _CogLineFindResult.LineRotation, 0); _CogTransForm.InputImage = _SrcImage; _CogTransForm.Region = _AffineRegion; _CogTransForm.Run(); CogCopyRegionTool _CopyRegion = new CogCopyRegionTool(); _CopyRegion.InputImage = _CogTransForm.OutputImage; _CopyRegion.DestinationImage = _SrcImage; _CopyRegion.RunParams.ImageAlignmentEnabled = true; _CopyRegion.Region = null; _CopyRegion.Run(); _DestImage = (CogImage8Grey)_CopyRegion.OutputImage; if (true == Inspection(_DestImage)) { GetResult(); } if (FindLineResults != null) { _CogLineFindResult.StartX = FindLineResults.GetLineSegment().StartX; _CogLineFindResult.StartY = FindLineResults.GetLineSegment().StartY; _CogLineFindResult.EndX = FindLineResults.GetLineSegment().EndX; _CogLineFindResult.EndY = FindLineResults.GetLineSegment().EndY; _CogLineFindResult.Length = FindLineResults.GetLineSegment().Length; _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; _CogLineFindResult.PointCount = FindLineResults.Count; _CogLineFindResult.IsGood = true; } else { _CogLineFindResult.IsGood = false; } GC.Collect(); } else { _CogLineFindResult.Rotation = FindLineResults.GetLineSegment().Rotation; double _Rotation = 0; _Rotation = _CogLineFindResult.Rotation * 180 / Math.PI; _CogLineFindResult.IsGood = true; } } catch { _CogLineFindResult.IsGood = false; } } else { _CogLineFindResult.IsGood = false; } return(_Result); }
private void 研究图像缝合ToolStripMenuItem_Click(object sender, EventArgs e) { CogImageFile imagefile_0 = new CogImageFile(); imagefile_0.Open(Application.StartupPath + "/../../../street/street_0.bmp", CogImageFileModeConstants.Read); CogImage24PlanarColor image_24_0 = new CogImage24PlanarColor(); image_24_0 = (CogImage24PlanarColor)imagefile_0[0]; CogImage8Grey imageGray8_0 = CogImageConvert.GetIntensityImage(image_24_0, 0, 0, image_24_0.Width, image_24_0.Height); CogImageFile imagefile_1 = new CogImageFile(); imagefile_1.Open(Application.StartupPath + "/../../../street/street_1.bmp", CogImageFileModeConstants.Read); CogImage24PlanarColor image_24_1 = new CogImage24PlanarColor(); image_24_1 = (CogImage24PlanarColor)imagefile_1[0]; CogImage8Grey imageGray8_1 = CogImageConvert.GetIntensityImage(image_24_1, 0, 0, image_24_1.Width, image_24_1.Height); CogImageFile imagefile_2 = new CogImageFile(); imagefile_2.Open(Application.StartupPath + "/../../../street/street_2.bmp", CogImageFileModeConstants.Read); CogImage24PlanarColor image_24_2 = new CogImage24PlanarColor(); image_24_2 = (CogImage24PlanarColor)imagefile_2[0]; CogImage8Grey imageGray8_2 = CogImageConvert.GetIntensityImage(image_24_2, 0, 0, image_24_2.Width, image_24_2.Height); // 灰度图像 //CogImage8Grey image8 = (CogImage8Grey)m_tb.GetScriptTerminalData("imageInput"); CogImage8Grey image8 = (CogImage8Grey)m_tb.GetScriptTerminalData("OutputImage"); image8 = imageGray8_0.Copy(); CogToolCollection tbTc = m_tb.Tools; //tbTc. if (false) { image8 = (CogImage8Grey)((CogImageFileTool)tbTc["CogImageFileTool1"]).OutputImage; } CogImage8Grey image_002 = new CogImage8Grey(); //image_002 = image8; image_002 = image8.Copy(); CogImage8Grey image_003 = image8.Copy(); // 将各个图像进行缝合组成一个完整的大图 // 灰度图像 //CogIPOneImageTool imageCtrl_02 = (CogIPOneImageTool)mToolBlock.Tools["CogIPOneImageTool2"]; CogRectangle rt = new CogRectangle(); rt.SetCenterWidthHeight(0, 0, image8.Width * 3, image8.Height * 3); CogImage8Grey m_gray = rt.CreateRLE(128, 0).CreateImage8Grey(); //imageCtrl_02.InputImage = m_gray; // CogImage8Grey inputImage = ( CogImage8Grey ) image8; // tb.SetScriptTerminalData("Input", inputImage); CogImageStitch stt = new CogImageStitch(); CogTransform2DLinear rootFromBlending = new CogTransform2DLinear(); //缩放,旋转,平移 rootFromBlending.SetScalingsRotationsTranslation(1, 1, 0, 0, 0, 0); // rootFromBlending.SetScalingsRotationTranslation(); stt.AllocateBlendingBuffer(image8.Width * 3, image8.Height * 3, rootFromBlending); //stt.BlendImageIntoBuffer(image8, m_gray); stt.BlendImageIntoBuffer(imageGray8_0, imageGray8_0, m_gray, 0, 0); stt.BlendImageIntoBuffer(imageGray8_1, imageGray8_1, m_gray, image8.Width, image8.Height); stt.BlendImageIntoBuffer(imageGray8_2, imageGray8_2, m_gray, image8.Width * 2, image8.Height * 2); stt.FillDestinationImageFromBuffer(m_gray); // BlendImageIntoBuffer( CogImage8Grey, CogImage8Grey, CogImage8Grey, Int32, Int32 ) // CogCopyRegionTool ccft = new CogCopyRegionTool(); //switch ( true ) //{ //case : // break; //} cogRecordDisplay1.Image = m_gray; cogRecordDisplay1.Fit(); }