今天在用 VS2013 C# 调用 cognex 的QuickBuild做程序时发生一个错误,如下所示
混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集
网上搜索得到解决办法:
在app.config中添加一个配置节:startup
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
下面为一个例子,
private void Test()
{
string FileName = @"D:\VS2013\C#与QuickBuild\TestImg\2.bmp";
Bitmap fileBitmap = new Bitmap(FileName);
CogImage8Grey CogImg8 = new CogImage8Grey(fileBitmap);
CogFindCircle FindCircleParams = new CogFindCircle();
FindCircleParams.NumCalipers = 50;
FindCircleParams.CaliperProjectionLength = 5;
FindCircleParams.CaliperSearchDirection = CogFindCircleSearchDirectionConstants.Outward;
FindCircleParams.CaliperSearchLength = 30;
FindCircleParams.ExpectedCircularArc.AngleStart = 0;
FindCircleParams.ExpectedCircularArc.AngleSpan = 360;
FindCircleParams.ExpectedCircularArc.CenterX = 245;
FindCircleParams.ExpectedCircularArc.CenterY = 215;
FindCircleParams.ExpectedCircularArc.Radius = 80;
CogFindCircleTool FindCircleTool = new CogFindCircleTool();
FindCircleTool.InputImage = CogImg8;
FindCircleTool.RunParams = FindCircleParams;
FindCircleTool.Run();
CogCircle theFindedCircle = FindCircleTool.Results.GetCircle();
string Result = theFindedCircle.Radius.ToString("0.000");
}
各个参数可以按照quickbuild的工具来设置。
注意要引用各个命名空间,FindCircleTool 的命名空间实在 Cognex.visionPro.Caliper里面