public static EImageBW8 ImageToEImageBW8(Image image) { EImageBW8 eImageBW8 = null; try { eImageBW8 = new EImageBW8(); Bitmap bitmap = (Bitmap)image; Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); eImageBW8.SetImagePtr(bitmap.Width, bitmap.Height, bmpData.Scan0); bitmap.UnlockBits(bmpData); } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(eImageBW8); }
private float ScalingRatio(EImageBW8 inputImage, PictureBox display) { float scalingRatio = 1; try { //計算Picturebox與顯示影像的比例,以便將影像縮放並且完整呈現到picturebox上。 float PictureBoxSizeRatio = (float)display.Width / display.Height; float ImageSizeRatio = (float)inputImage.Width / inputImage.Height; if (ImageSizeRatio > PictureBoxSizeRatio) { scalingRatio = (float)display.Width / inputImage.Width; } else { scalingRatio = (float)display.Height / inputImage.Height; } } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(scalingRatio); }
public override EImageBW8 Run(EImageBW8 img) { if (!Enable) { return(img); } EImageBW8 imgBw8 = new EImageBW8(); imgBw8.SetSize(img); switch (Mode) { case MyThresholdMode.Auto: EBW8 value1 = EasyImage.AutoThreshold(img, EThresholdMode.MinResidue); AbsoluteValue = value1.Value; break; case MyThresholdMode.Absolute: break; case MyThresholdMode.Relative: EBW8 value2 = EasyImage.AutoThreshold(img, EThresholdMode.Relative, RelativeValue); AbsoluteValue = value2.Value; break; default: break; } EasyImage.Threshold(img, imgBw8, AbsoluteValue); img.Dispose(); img = new EImageBW8(); return(imgBw8); }
public void SaveEMatcher_Blank( PatternMatcherParameters param, string pattern1_FilePath, string pattern2_FilePath, string pattern1_ImageFilePath, string pattern2_ImageFilePath) { EImageBW8 blackImage = new EImageBW8(512, 512); EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), blackImage); // make it black EROIBW8 blackEROI = new EROIBW8(); blackEROI.OrgX = 0; blackEROI.OrgY = 0; blackEROI.Width = 512; blackEROI.Height = 512; blackEROI.Attach(blackImage); TeachAndSaveEMatcher( param, blackEROI, blackEROI, pattern1_FilePath, pattern2_FilePath, pattern1_ImageFilePath, pattern2_ImageFilePath); }
/// <summary> /// 图片均衡操作,将传入图片自动转换,imgWidth:设定图片宽度,imgHeight图片设定高度 /// 图片(forexample:a.bmp)另存为同文件夹下面的_a.bmp /// </summary> /// <param name="ImagePath"></param> public void QualizerImage(string ImagePath, int imgWidth, int imgHeight) { try { if ((ImagePath.Length == 0) || (!File.Exists(ImagePath))) { return; } EImageBW8 EBW8ImageOrig = new EImageBW8(); // EImageBW8 instance EImageBW8 EBW8ImageDest = new EImageBW8(); // EImageBW8 instance EBW8ImageOrig.SetSize(imgWidth, imgHeight); // Make image black EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageOrig); EBW8ImageOrig.Load(ImagePath); EBW8ImageDest.SetSize(imgWidth, imgHeight); // Make image black EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageDest); EBW8ImageDest.SetSize(EBW8ImageOrig); EasyImage.Equalize(EBW8ImageOrig, EBW8ImageDest); EBW8ImageOrig.Dispose(); //EBW8ImageDest.Save(ImagePath); EBW8ImageDest.Save(ImageSaveAsPath(ImagePath)); } catch { throw; } }
public ImgDictionary(BaseConfig baseConfig, EImageBW8 img, int index) { _name = baseConfig.ToolName + ".Img"; _img = img; Config = baseConfig; Index = index; }
public override EImageBW8 Run(EImageBW8 img) { if (!Enable) { return(img); } EImageBW8 imgBw8 = new EImageBW8(); imgBw8.SetSize(img); switch (Type) { case MorphologyType.Square: EasyImage.DilateBox(img, imgBw8, Width); break; case MorphologyType.Rectangle: EasyImage.DilateBox(img, imgBw8, Width, Height); break; case MorphologyType.Circle: EasyImage.DilateDisk(img, imgBw8, Width); break; default: EasyImage.DilateBox(img, imgBw8, Width); break; } img.Dispose(); img = new EImageBW8(); return(imgBw8); }
/*==============================================================================================*/ private bool FindBlob(EImageBW8 inputImage, byte threshold = 128, bool findBlack = true, bool findWhite = false) { bool reSuccess = false; try { eImageEncoder.GrayscaleSingleThresholdSegmenter.BlackLayerEncoded = findBlack; eImageEncoder.GrayscaleSingleThresholdSegmenter.WhiteLayerEncoded = findWhite; eImageEncoder.SegmentationMethod = ESegmentationMethod.GrayscaleSingleThreshold; eImageEncoder.GrayscaleSingleThresholdSegmenter.Mode = EGrayscaleSingleThreshold.Absolute; eImageEncoder.GrayscaleSingleThresholdSegmenter.AbsoluteThreshold = threshold; eImageEncoder.Encode(inputImage, Base); reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool ShowImage(PictureBox display, EImageBW8 image) { bool reSuccess = false; try { Bitmap bmp = new Bitmap(image.Width, image.Height); image.Draw(Graphics.FromImage(bmp), zoomX, zoomY, panX - mouseX, panY - mouseY); if (display.InvokeRequired) { display.Invoke(new Action(() => { display.BackgroundImage = bmp; })); } else { display.BackgroundImage = bmp; } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool FindPattern(EImageBW8 inputImage, ref EFoundPattern[] foundPattern) { bool reSuccess = false; try { foundPattern = Base.Find(inputImage); if (foundPattern != null) { if (foundPattern.Length >= 1) { reSuccess = true; } } } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool ShowTrainImage(PictureBox display, EImageBW8 trainImage) { bool reSuccess = false; try { float scalingRatio = ScalingRatio(trainImage, display); Bitmap bmp = new Bitmap(display.Width, display.Height); trainImage.Draw(Graphics.FromImage(bmp), scalingRatio); if (display.InvokeRequired) { display.Invoke(new Action(() => { display.BackgroundImage = bmp; })); } else { display.BackgroundImage = bmp; } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool TrainPattern(EROIBW8 trainROI, ref EImageBW8 trainImage, EPatternType patternType, float lightBalance = 0, bool autoTransitionThickness = true, int transitionThickness = 6) { bool reSuccess = false; try { lightBalance = lightBalance > 1 ? 1 : lightBalance; lightBalance = lightBalance < -1 ? -1 : lightBalance; Base.PatternType = patternType; Base.LightBalance = lightBalance; Base.AutoTransitionThickness = autoTransitionThickness; Base.TransitionThickness = 6; Base.Learn(trainROI); Base.CopyLearntPattern(trainImage); reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool FindPattern(EImageBW8 inputImage, ref EFoundPattern[] foundPattern, int maxInstances, float minScore, EFindContrastMode contrastMode, float angleBias = 0, float angleTolerance = 25, float scaleBias = 1, float scaleTolerance = 0.25f, int scaleSearchExtent = 3) { bool reSuccess = false; try { Base.MaxInstances = (int)maxInstances; Base.MinScore = minScore; Base.ContrastMode = contrastMode; Base.AngleBias = angleBias; //角度偏差 Base.AngleTolerance = angleTolerance; //角度公差 Base.ScaleBias = scaleBias; //縮放偏差 Base.ScaleTolerance = scaleTolerance; //縮放公差 Base.ScaleSearchExtent = scaleSearchExtent; reSuccess = FindPattern(inputImage, ref foundPattern); } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
private bool GetSample(EImageBW8 inputImage, ref DataTable result) { bool reSuccess = false; try { result.Clear(); EPoint point = new EPoint(); for (int i = 0; i < Base.NumSamples; i++) { Base.MeasureSample(inputImage, i); if (Base.GetSample(point, i)) { float centerX = Base.GetMeasuredPoint().X; float centerY = Base.GetMeasuredPoint().Y; int amplitude = Base.GetMeasuredPeak().Amplitude; int area = Base.GetMeasuredPeak().Area; result.Rows.Add(i + 1, centerX, centerY, amplitude, area); } } reSuccess = true; } catch (EException exc) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true); } return(reSuccess); }
/// <summary> /// 从图片中获得DecodeString /// </summary> /// <param name="imagePath"></param> /// <returns></returns> public bool GetDecodeStrbyPath(string imagePath, int DeviceID) { try { if ((imagePath.Length == 0) || (!File.Exists(imagePath))) { return(false); } EMatrixCodeReader EMatrixCodeReader1 = new EMatrixCodeReader(); // EMatrixCodeReader instance EMatrixCodeReader1.TimeOut = 3000000; EMatrixCode EMatrixCodeReader1Result = null; // EMatrixCode EImageBW8 EBW8Image1 = new EImageBW8(); // EImageBW8 instance EBW8Image1.Load(imagePath); EMatrixCodeReader1Result = EMatrixCodeReader1.Read(EBW8Image1); //GlobalVar.gl_str_decode[DeviceID] = EMatrixCodeReader1Result.DecodedString; return(true); } catch { return(false); throw; } }
public BaseEvent(Task task) { ParentTask = task; ResultData = new Result(); InputImg = new EImageBW8(); Initialize(); }
public EImageBW8 ConvertBitmapToEImageBW8(Bitmap bmp) { EImageBW8 EBW8Image1 = new EImageBW8(bmp.Width, bmp.Height); // EImageBW8 instance try { Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); //锁定位图 System.Drawing.Imaging.BitmapData bmpdata_src = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); //获取首行地址 IntPtr pScan0 = bmpdata_src.Scan0; unsafe { try { for (int Height = 0; Height < bmpdata_src.Height; Height++) { byte *pSrc = (byte *)pScan0; pSrc += bmpdata_src.Stride * Height; byte *pDest = (byte *)EBW8Image1.GetImagePtr(0, Height); for (int Width = 0; Width < bmpdata_src.Width; Width++) { pDest[0] = (byte)(pSrc[0] * 0.299 + pSrc[1] * 0.587 + pSrc[2] * 0.114); pSrc += 3; pDest++; } } } catch { } } bmp.UnlockBits(bmpdata_src); } catch { } return(EBW8Image1); }
/// <summary> /// 灰度&对比度处理,图片另存为imagePath\_*.* /// 图片(forexample:a.bmp)另存为同文件夹下面的_a.bmp /// </summary> /// <param name="ImagePath"></param> /// <param name="Val_gain"></param> /// <param name="Val_offSet"></param> public EImageBW8 EImageBW8GainOff(EImageBW8 ImageSource, float Val_gain, float Val_offSet) { EImageBW8 EBW8ImageDest = new EImageBW8(ImageSource.Width, ImageSource.Height); // EImageBW8 instance try { EasyImage.GainOffset(ImageSource, EBW8ImageDest, Val_gain, Val_offSet); } catch { } return(EBW8ImageDest); }
private void _FindLearnPattern(EImageBW8 bw8, Rectangle rect, EImageBW8 dontcare, float lightbalance = 0) { EBW8ImageRoi1.Attach(bw8); EBW8ImageRoi1.SetPlacement(rect.Location.X + 1, rect.Location.Y + 1, rect.Width - 8, rect.Height - 8); m_find.PatternType = EPatternType.ConsistentEdges; //EPatternType.ContrastingRegions; m_find.MinScore = GlobalVar.MinScore; m_find.Learn(EBW8ImageRoi1, dontcare); if (lightbalance > -1.0 && lightbalance < 1.0f) { m_find.LightBalance = lightbalance; } }
public override EImageBW8 Run(EImageBW8 img) { if (!Enable) { return(img); } EImageBW8 imgBw8 = new EImageBW8(); imgBw8.SetSize(img); EasyImage.Median(img, imgBw8); img.Dispose(); img = new EImageBW8(); return(imgBw8); }
public override EImageBW8 Run(EImageBW8 img) { if (!Enable) { return(img); } EImageBW8 imgBw8 = new EImageBW8(); imgBw8.SetSize(img); EasyImage.GainOffset(img, imgBw8, Gain, Offset); img.Dispose(); img = new EImageBW8(); return(imgBw8); }
public EImageBW8 Execute(EImageBW8 original, double zoomFactor) { try { EImageBW8 resized = new EImageBW8(original); resized.SetSize((int)(original.Width * zoomFactor), (int)(original.Height * zoomFactor)); return(resized); } catch (Exception e) { //Maximum Size Reached throw new Exception("ResizeImage Failed" + e.Message); } }
public clsEasyFindLine(PictureBox display, ELineGauge eLineGauge) { Display = display; Base = eLineGauge; InputImage = new EImageBW8(); zoomX = Base.ZoomX; zoomY = Base.ZoomY; sampleTable = new DataTable("SampleTable"); sampleTable.Columns.Add("PointIndex"); sampleTable.Columns.Add("Center_X"); sampleTable.Columns.Add("Center_Y"); sampleTable.Columns.Add("Amplitude"); sampleTable.Columns.Add("Area"); }
private void btn_loadImg_Click(object sender, EventArgs e) { if (mPicBox1.LoadImg()) { roi.Attach(mPicBox1.Image); btn_action.Visible = true; btn_learn.Visible = true; btn_loadMoudle.Visible = true; btn_save.Visible = true; btn_process.Visible = true; ckbox_inRoi.Visible = true; copyImg = new EImageBW8(); copyImg.SetSize(mPicBox1.Image); EasyImage.Copy(mPicBox1.Image, copyImg); } }
internal bool ShapeFind(ref Bitmap bmp) { EImageBW8 bw8 = ConvertBitmapToEImageBW8(bmp); m_FindResult = m_find.Find(bw8); #region 目标绘图 if (m_FindResult.Length > 0) { m_FindResult[0].DrawFeaturePoints = true; using (Graphics gp = Graphics.FromImage(bmp)) { m_FindResult[0].Draw(gp); } } #endregion return(m_FindResult.Length > 0); }
/// <summary> /// Find学习ROI【返回绘制ROI后的图形】 /// </summary> /// <param name="image">图像</param> /// <param name="rect">ROI</param> /// <param name="dontcare">忽略区域</param> /// <param name="lightbalance">光平衡</param> internal Bitmap FindLearnPattern(Bitmap bmp, Rectangle rect, Bitmap dontcare, float lightbalance = 0) { EImageBW8 bw8 = ConvertBitmapToEImageBW8(bmp); EImageBW8 bw8dontcare = ConvertBitmapToEImageBW8(dontcare); _FindLearnPattern(bw8, rect, bw8dontcare, lightbalance); #region 模型绘图 using (Graphics gp = Graphics.FromImage(bmp)) { Color centerpen = Color.FromArgb(250, 37, 69); Color modepen = Color.FromArgb(0, 255, 0); m_find.Draw(gp, new ERGBColor(centerpen.R, centerpen.G, centerpen.B)); //中心十字 m_find.DrawModel(gp, new ERGBColor(modepen.R, modepen.G, modepen.B)); //特征点 } #endregion return(bmp); }
public clsEasyFindPattern(PictureBox display, EPatternFinder ePatternFinder) { Display = display; Base = ePatternFinder; inputImage = new EImageBW8(); trainROI = new EROIBW8(); trainImage = new EImageBW8(); dragHandle = EDragHandle.NoHandle; patternTable = new DataTable("PatternTable"); patternTable.Columns.Add("Index"); patternTable.Columns.Add("Score"); patternTable.Columns.Add("Center_X"); patternTable.Columns.Add("Center_Y"); patternTable.Columns.Add("Angle (Deg)"); patternTable.Columns.Add("Scale (%)"); }
private void initEvision() { try { MatrixDecode decoder = new MatrixDecode(); EMatrixCode EMatrixCodeReaderResult = new EMatrixCode(); EMatrixCodeReader EMatrixCodeReader1 = new EMatrixCodeReader(); EMatcher match = new EMatcher(); Bitmap bmp = new Bitmap(640, 480); EImageBW8 bw8image = ConvertBitmapToEImageBW8(bmp); } catch { } finally { this.DialogResult = DialogResult.OK; //startMain.Set(); } }
public override EImageBW8 Run(EImageBW8 img) { if (!Enable) { return(img); } EImageBW8 imgBw8 = new EImageBW8(); float a = 0f, x = 0f, y = 0f; if (Value % 180 < 90) { //当前角度 a = (float)Math.Atan2((float)img.Height / 2, (float)img.Width / 2); //旋转后角度 float b = a + Value % 90 * ((float)Math.PI / 180); float c = a - Value % 90 * ((float)Math.PI / 180); //斜边 float z = (float)Math.Sqrt(img.Width * img.Width + img.Height * img.Height) / 2; //xy增量 x = (float)(Math.Cos(c) - Math.Cos(a)) * z; y = (float)(Math.Sin(b) - Math.Sin(a)) * z; //设置新图片大小 imgBw8.SetSize((int)(img.Width + 2 * x), (int)(img.Height + 2 * y)); } else if (Value % 180 >= 90) { //当前角度 a = (float)Math.Atan2((float)img.Height / 2, (float)img.Width / 2); //旋转后角度 float b = a + Value % 90 * ((float)Math.PI / 180); float c = a - Value % 90 * ((float)Math.PI / 180); //斜边 float z = (float)Math.Sqrt(img.Width * img.Width + img.Height * img.Height) / 2; //xy增量 y = (float)(Math.Cos(c) - Math.Cos(a)) * z; x = (float)(Math.Sin(b) - Math.Sin(a)) * z; //设置新图片大小 imgBw8.SetSize((int)(img.Height + 2 * x), (int)(img.Width + 2 * y)); } EasyImage.ScaleRotate(img, (float)img.Width / 2, (float)img.Height / 2, (float)imgBw8.Width / 2, (float)imgBw8.Height / 2, 1, 1, Value, imgBw8, 0); img.Dispose(); img = new EImageBW8(); return(imgBw8); }
public clsEasyFindBlob(PictureBox display, ECodedImage2 eCodedImage2) { Display = display; Base = eCodedImage2; InputImage = new EImageBW8(); eImageEncoder = new EImageEncoder(); eObjectSelection = new EObjectSelection(); blobTable = new DataTable("BlobTable"); blobTable.Columns.Add("Index"); blobTable.Columns.Add("Area"); blobTable.Columns.Add("Center_X"); blobTable.Columns.Add("Center_Y"); Display.MouseDown += PictureBox_MouseDown; Display.MouseMove += PictureBox_MouseMove; Display.MouseUp += PictureBox_MouseUp; Display.MouseWheel += PictureBox_MouseWheel; Display.MouseHover += PictureBox_MouseHover; }