好看的手机网站模板,智能建站程序,网站建设技术是干嘛的,wordpress邮件功能用不了划痕检测,我这里用到的是Sobel算子和blob斑点匹配以及blob里面的形态学调整
Sobel 是一种在数字图像处理和计算机视觉领域广泛应用的算法#xff0c;主要用于边缘检测 脚本展示
#region namespace imports
using System;
using System.Collections;
using System.Drawing;
… 划痕检测,我这里用到的是Sobel算子和blob斑点匹配以及blob里面的形态学调整
Sobel 是一种在数字图像处理和计算机视觉领域广泛应用的算法主要用于边缘检测 脚本展示
#region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.ImageProcessing;
using Cognex.VisionPro.Blob;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicCollection dt new CogGraphicCollection();/// summary/// Called when the parent tool is run./// Add code here to customize or replace the normal run behavior./// /summary/// param namemessageSets the Message in the tools RunStatus./param/// param nameresultSets the Result in the tools RunStatus/param/// returnsTrue if the tool should run normally,/// False if GroupRun customizes run behavior/returnspublic override bool GroupRun(ref string message, ref CogToolResultConstants result){// To let the execution stop in this script when a debugger is attached, uncomment the following lines.// #if DEBUG// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();// #endifCogBlobTool blob mToolBlock.Tools[CogBlobTool1]as CogBlobTool;// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);for(int i 0;i blob.Results.GetBlobs().Count;i){double x blob.Results.GetBlobs()[i].CenterOfMassX;double y blob.Results.GetBlobs()[i].CenterOfMassY;dt.Add(Create(x, y));}return false;}private CogRectangleAffine Create(double x, double y){CogRectangleAffine tt new CogRectangleAffine();tt.SideXLength 8;tt.SideYLength 14;tt.CenterX x;tt.CenterY y;tt.Color CogColorConstants.Red;tt.LineWidthInScreenPixels 4;return tt;}#region When the Current Run Record is Created/// summary/// Called when the current record may have changed and is being reconstructed/// /summary/// param namecurrentRecord/// The new currentRecord is available to be initialized or customized./parampublic override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord){}#endregion#region When the Last Run Record is Created/// summary/// Called when the last run record may have changed and is being reconstructed/// /summary/// param namelastRecord/// The new last run record is available to be initialized or customized./parampublic override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord){foreach(ICogGraphic s in dt){mToolBlock.AddGraphicToRunRecord(s, lastRecord, CogSobelEdgeTool1.InputImage, script);}}#endregion#region When the Script is Initialized/// summary/// Perform any initialization required by your script here/// /summary/// param namehostThe host tool/parampublic override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host){// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion} 效果 下面的我们先用Pixel 通过直方图调节来突出边缘和表面特征 在通过调节二值化阈值等来突出 脚本
#region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.PixelMap;
using Cognex.VisionPro.Blob;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicCollection dt new CogGraphicCollection();CogPolygon polygon;/// summary/// Called when the parent tool is run./// Add code here to customize or replace the normal run behavior./// /summary/// param namemessageSets the Message in the tools RunStatus./param/// param nameresultSets the Result in the tools RunStatus/param/// returnsTrue if the tool should run normally,/// False if GroupRun customizes run behavior/returnspublic override bool GroupRun(ref string message, ref CogToolResultConstants result){// To let the execution stop in this script when a debugger is attached, uncomment the following lines.// #if DEBUG// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();// #endifdt.Clear();CogBlobTool blob mToolBlock.Tools[CogBlobTool1]as CogBlobTool;// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);for(int i 0;i blob.Results.GetBlobs().Count;i){polygon new CogPolygon();polygon blob.Results.GetBlobs()[i].GetBoundary();polygon.Color CogColorConstants.Red;dt.Add(polygon);}return false;}#region When the Current Run Record is Created/// summary/// Called when the current record may have changed and is being reconstructed/// /summary/// param namecurrentRecord/// The new currentRecord is available to be initialized or customized./parampublic override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord){}#endregion#region When the Last Run Record is Created/// summary/// Called when the last run record may have changed and is being reconstructed/// /summary/// param namelastRecord/// The new last run record is available to be initialized or customized./parampublic override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord){foreach(ICogGraphic s in dt){mToolBlock.AddGraphicToRunRecord(s, lastRecord, CogPixelMapTool1.InputImage, script);}}#endregion#region When the Script is Initialized/// summary/// Perform any initialization required by your script here/// /summary/// param namehostThe host tool/parampublic override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host){// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion}
效果 #region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.ImageProcessing;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.CalibFix;
using Cognex.VisionPro.PixelMap;
using Cognex.VisionPro.Blob;
#endregionpublic class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{#region Private Member Variablesprivate Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;#endregionCogGraphicCollection dt new CogGraphicCollection();CogGraphicLabel label new CogGraphicLabel();/// summary/// Called when the parent tool is run./// Add code here to customize or replace the normal run behavior./// /summary/// param namemessageSets the Message in the tools RunStatus./param/// param nameresultSets the Result in the tools RunStatus/param/// returnsTrue if the tool should run normally,/// False if GroupRun customizes run behavior/returnspublic override bool GroupRun(ref string message, ref CogToolResultConstants result){// To let the execution stop in this script when a debugger is attached, uncomment the following lines.// #if DEBUG// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();// #endifdt.Clear();CogBlobTool blob mToolBlock.Tools[CogBlobTool1]as CogBlobTool;CogPolarUnwrapTool polar mToolBlock.Tools[CogPolarUnwrapTool1]as CogPolarUnwrapTool;// Run each tool using the RunTool functionforeach(ICogTool tool in mToolBlock.Tools)mToolBlock.RunTool(tool, ref message, ref result);for(int i 0;i blob.Results.GetBlobs().Count;i){double x blob.Results.GetBlobs()[i].CenterOfMassX;double y blob.Results.GetBlobs()[i].CenterOfMassY;double lastx,lasty;polar.RunParams.GetInputPointFromOutputPoint(polar.InputImage, polar.Region, x, y, out lastx, out lasty);dt.Add(CreateCircle(lastx, lasty));}if(blob.Results.GetBlobs().Count 0){label.SetXYText(100, 100, NG);label.Alignment CogGraphicLabelAlignmentConstants.TopLeft;label.Font new Font(楷体, 20);label.Color CogColorConstants.Red;dt.Add(label);}else{label.SetXYText(100, 100, Pass);label.Alignment CogGraphicLabelAlignmentConstants.TopLeft;label.Font new Font(楷体, 20);label.Color CogColorConstants.Green;dt.Add(label);}return false;}private CogCircle CreateCircle(double x, double y){CogCircle co new CogCircle();co.CenterX x;co.CenterY y;co.Radius 30;co.Color CogColorConstants.Red;co.LineWidthInScreenPixels 6;return co;}#region When the Current Run Record is Created/// summary/// Called when the current record may have changed and is being reconstructed/// /summary/// param namecurrentRecord/// The new currentRecord is available to be initialized or customized./parampublic override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord){}#endregion#region When the Last Run Record is Created/// summary/// Called when the last run record may have changed and is being reconstructed/// /summary/// param namelastRecord/// The new last run record is available to be initialized or customized./parampublic override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord){foreach(ICogGraphic s in dt){mToolBlock.AddGraphicToRunRecord(s, lastRecord, CogImageConvertTool1.InputImage, );}}#endregion#region When the Script is Initialized/// summary/// Perform any initialization required by your script here/// /summary/// param namehostThe host tool/parampublic override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host){// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVEbase.Initialize(host);// Store a local copy of the script hostthis.mToolBlock ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));}#endregion} 文章转载自: http://www.morning.mrnnb.cn.gov.cn.mrnnb.cn http://www.morning.dmjhp.cn.gov.cn.dmjhp.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.ptmgq.cn.gov.cn.ptmgq.cn http://www.morning.ymwnc.cn.gov.cn.ymwnc.cn http://www.morning.qwqzk.cn.gov.cn.qwqzk.cn http://www.morning.bkfdf.cn.gov.cn.bkfdf.cn http://www.morning.qxmnf.cn.gov.cn.qxmnf.cn http://www.morning.tgmfg.cn.gov.cn.tgmfg.cn http://www.morning.flfxb.cn.gov.cn.flfxb.cn http://www.morning.nhpgm.cn.gov.cn.nhpgm.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.zwznz.cn.gov.cn.zwznz.cn http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn http://www.morning.yfffg.cn.gov.cn.yfffg.cn http://www.morning.qgzmz.cn.gov.cn.qgzmz.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn http://www.morning.fxpyt.cn.gov.cn.fxpyt.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.rcww.cn.gov.cn.rcww.cn http://www.morning.fprll.cn.gov.cn.fprll.cn http://www.morning.ryjqh.cn.gov.cn.ryjqh.cn http://www.morning.rzmsl.cn.gov.cn.rzmsl.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.rqnml.cn.gov.cn.rqnml.cn http://www.morning.lwzpp.cn.gov.cn.lwzpp.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.sjftk.cn.gov.cn.sjftk.cn http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.rpwht.cn.gov.cn.rpwht.cn http://www.morning.xqndf.cn.gov.cn.xqndf.cn http://www.morning.dfrenti.com.gov.cn.dfrenti.com http://www.morning.gthgf.cn.gov.cn.gthgf.cn http://www.morning.jcfqg.cn.gov.cn.jcfqg.cn http://www.morning.wmfny.cn.gov.cn.wmfny.cn http://www.morning.msxhb.cn.gov.cn.msxhb.cn http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.krdmn.cn.gov.cn.krdmn.cn http://www.morning.sgrdp.cn.gov.cn.sgrdp.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn http://www.morning.jcfqg.cn.gov.cn.jcfqg.cn http://www.morning.mnyzz.cn.gov.cn.mnyzz.cn http://www.morning.jhwwr.cn.gov.cn.jhwwr.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.krtcjc.cn.gov.cn.krtcjc.cn http://www.morning.ccdyc.cn.gov.cn.ccdyc.cn http://www.morning.zstbc.cn.gov.cn.zstbc.cn http://www.morning.srjbs.cn.gov.cn.srjbs.cn http://www.morning.zstry.cn.gov.cn.zstry.cn http://www.morning.hfrbt.cn.gov.cn.hfrbt.cn http://www.morning.htbsk.cn.gov.cn.htbsk.cn http://www.morning.bfkrf.cn.gov.cn.bfkrf.cn http://www.morning.dxqfh.cn.gov.cn.dxqfh.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.sgwr.cn.gov.cn.sgwr.cn http://www.morning.rbxsk.cn.gov.cn.rbxsk.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.lmxzw.cn.gov.cn.lmxzw.cn http://www.morning.mstrb.cn.gov.cn.mstrb.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.gnwpg.cn.gov.cn.gnwpg.cn http://www.morning.krtky.cn.gov.cn.krtky.cn http://www.morning.kzslk.cn.gov.cn.kzslk.cn http://www.morning.ftrpvh.cn.gov.cn.ftrpvh.cn http://www.morning.sgbjh.cn.gov.cn.sgbjh.cn http://www.morning.pskjm.cn.gov.cn.pskjm.cn http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn http://www.morning.nbgfk.cn.gov.cn.nbgfk.cn http://www.morning.clbzy.cn.gov.cn.clbzy.cn http://www.morning.gyrdn.cn.gov.cn.gyrdn.cn http://www.morning.fjgwg.cn.gov.cn.fjgwg.cn http://www.morning.wsnbg.cn.gov.cn.wsnbg.cn