网站论坛制作,搜索公司信息的网站,莱芜金点子招聘网最新招聘,怎么根据已有网站做新网站2D图像拼接的3种情景
1.一只相机取像位置固定#xff0c;或者多只相机固定位置拍图#xff0c;硬拷贝拼图#xff0c;采用CopyRegion工具实现 2.一只或多只相机在多个位置拍照#xff0c;相机视野互相重叠#xff0c;基于Patmax特征定位后#xff0c;无缝 拼图#xff…2D图像拼接的3种情景
1.一只相机取像位置固定或者多只相机固定位置拍图硬拷贝拼图采用CopyRegion工具实现 2.一只或多只相机在多个位置拍照相机视野互相重叠基于Patmax特征定位后无缝 拼图采用CogImageStitch类实现 3.一只或多只相机在多个位置拍照相机视野只有小范围重叠或者不重叠无法使用 Patmax特征定位可以用标定板标定位置关系使用CogImageStitch类实现拼图. 注意此方法是是预先标定的位置关系如果采用1只相机多个位置拍摄需要机构保证重复运动的精度在允许范围内否则可能造成图像错位。 注意无论是哪种拼接方式单相机或是多相机拍照都需要尽量调节到同一个高度拍照否则可能造成图像重影模糊等问题
1.CopyRegionTool硬拷贝拼图 1.请参考QuickBuild自带例程 Script_Stitch_Job.vpp 2.在CogJob的作业属性-取像脚本中实现多张图像拷 贝拼接 3.注意CopyRegion工具的属性 DesinationImageAlignmentX和Y用于指定子图像在拼接大图的位置偏移 2.基于互相重叠的Patmax特征无缝拼接
请参考“TB_Patmax算法拼.vpp” 此VPP实现3张图像上下拼接其他拼接组合可以自行改写程序 流程 1).添加Patmax工具训练各个重叠特征注意相邻的两张图同样的特征使用同一个Patmax工具即可 2).载入第一张图像运行整个CogJob将图像给到TB_StitchImage1Patmax定位结果给到Image1Pose1注意不要用连线 3).对其他图像重复同样的工作中间的图像有两个PMA结果需要连2个Pose 4).TB_Stitch输出的图像即为拼接后图。 这里CogImageStitch类使用的方法
1).AllocateBlendingBuffer指定图像大小为拼接后图的尺寸Transform不需要特别设置在(0,0)附近即可Scale为1
2).分别为3张图建立CogTransform2DLinear第一个Transform建立在(0,0)位置, 其他图Transform关系依次Compose 前一个相邻Pose的Invert因为后一个是依据前一个的位置关系来偏移的。以上下3张图拼接为例就建立了图示的关系
3).将图像和Tansform关系分别传入不同的CogFixtureTool在图像中添加对应的坐标系。注意坐标系名称不能一样或者用代码AddSpace手动添加坐标系也可以
4).生成的带新坐标系的图像传入CogImageStitch工具用BlendImageIntoBuffer方法会将每张图像对应添加到拼接大图的对
应位置。
5).调用FillDestinationImageFromBuffer来生成拼接图完成。注意BlendImageInfoBuffer和OverwriteImage两种方法的区别Overwrite在像素重叠部分是互相覆盖了而Blend模式是按照不同权重混合起来因此更接近无缝拼接。 详细代码如下
public 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();// #endifCogImage8Grey Img1 (CogImage8Grey) this.Inputs.Image1;CogImage8Grey Img2 (CogImage8Grey) this.Inputs.Image2;CogImage8Grey Img3 (CogImage8Grey) this.Inputs.Image3;CogImage8Grey StitchedImg new CogImage8Grey(Img1.Width500, Img1.Height * 3);CogImageStitch mStitch new CogImageStitch();// CogImageStitch.FillDefaultWeightImage(StitchedImg);CogImage8Grey imgMask0 new CogImage8Grey(Img1.Width, Img1.Height);CogImageStitch.FillDefaultWeightImage(imgMask0);CogImage8Grey imgMask1 new CogImage8Grey(Img1.Width, Img1.Height);CogImageStitch.FillDefaultWeightImage(imgMask1);CogImage8Grey imgMask2 new CogImage8Grey(Img1.Width, Img1.Height);CogImageStitch.FillDefaultWeightImage(imgMask2);CogTransform2DLinear trans new CogTransform2DLinear();trans.Scaling 1;trans.TranslationX 10;trans.TranslationY 10;mStitch.AllocateBlendingBuffer(Img1.Width500, Img1.Height * 3, trans);CogCoordinateSpaceTree mSpace1 Img1.CoordinateSpaceTree;CogCoordinateSpaceTree mSpace2 Img2.CoordinateSpaceTree;CogCoordinateSpaceTree mSpace3 Img3.CoordinateSpaceTree;CogTransform2DLinear mTrans1 new CogTransform2DLinear();mTrans1.Scaling 1;mTrans1.TranslationX 0;mTrans1.TranslationY 0;mTrans1.Rotation 0;// mSpace1.AddSpace(, foo_0, mTrans1, true, CogAddSpaceConstants.ReplaceDuplicate);CogTransform2DLinear mTrans2 this.Inputs.Image2Pose1.Compose(this.Inputs.Image1Pose1.Invert());// mSpace2.AddSpace(, foo_1, mTrans2, true, CogAddSpaceConstants.ReplaceDuplicate);CogTransform2DLinear mTrans3 this.Inputs.Image3Pose2.Compose(this.Inputs.Image2Pose2.Invert()).Compose(mTrans2);// mSpace3.AddSpace(, foo_2, mTrans3, true, CogAddSpaceConstants.ReplaceDuplicate);/* mStitch.BlendImageIntoBuffer(Img1, null);mStitch.BlendImageIntoBuffer(Img2, null);mStitch.BlendImageIntoBuffer(Img3, null);*/ this.Tools.CogFixtureTool1.RunParams.UnfixturedFromFixturedTransform mTrans1;this.Tools.CogFixtureTool1.Run();this.Tools.CogFixtureTool2.RunParams.UnfixturedFromFixturedTransform mTrans2;this.Tools.CogFixtureTool2.Run();this.Tools.CogFixtureTool3.RunParams.UnfixturedFromFixturedTransform mTrans3;this.Tools.CogFixtureTool3.Run();mStitch.BlendImageIntoBuffer((CogImage8Grey)this.Tools.CogFixtureTool1.OutputImage, imgMask0);mStitch.BlendImageIntoBuffer((CogImage8Grey)this.Tools.CogFixtureTool2.OutputImage,imgMask1);mStitch.BlendImageIntoBuffer((CogImage8Grey)this.Tools.CogFixtureTool3.OutputImage,imgMask2); mStitch.FillDestinationImageFromBuffer(StitchedImg);// MessageBox.Show(mTrans3.TranslationX.ToString() mTrans3.TranslationY.ToString());this.Outputs.StitchedImage StitchedImg;return false;}3.使用标定板拼接
请参考“TB_标定板拼.vpp” 此VPP实现3张图像上下拼接其他拼接组合可以自行改写程序标定板可以使用二维码标定板也可以用Cognex标准标定板 如果使用二维码标定板不要求视野重叠使用带 Cognex标记的标定板则需要视野重叠以便于各个拍照位置建立统一的标定板坐标系。
流程如下 1).标定板放好固定不动。大小要能够覆盖整个拍照视野范围 2).3只相机或同一个相机的3个位置对标定板拍照执行。 CheckBoard标定得到outputImage和OutputImageMask注意此时每张图的输出坐标系都是标定片坐标系 3).打开距离标定板坐标系原点最近的那张图获取坐标原点在Root space下的X和Y坐标值利用标定板图计算图像的像素坐标与标定板坐标系的比例关系分别输入到 ToolBlock的dScale,dTransX, dTransY中 4).执行ToolBlock即可得到拼接后图像。 CogImageStitch类使用的方法 1).由于各张子图像已经采用标定板建立了标定板坐标系因此前面特征拼接方法不同的是这里不需要再自行建立坐标系关系使用标定板坐标系即可 2).但是在AllocateBlendingBuffer时需要指定RootFromBlendingBuffer的坐标系变换关系。由于BlendingBuffer分配时使用的标定板坐标系而图像是从rootspace下copy像素因此变换关系的比例和Translation需要在定义BlendingBuffer时指定。 3其他部分按照CogImageStitch的使用方法调用即可。 详细代码如下
public 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();// #endifCogImage8Grey Img1 (CogImage8Grey) this.Inputs.Image1;CogImage8Grey Img2 (CogImage8Grey) this.Inputs.Image2;CogImage8Grey Img3 (CogImage8Grey) this.Inputs.Image3;CogImage8Grey imgMask0 (CogImage8Grey) this.Inputs.CalibMask1;CogImage8Grey imgMask1 (CogImage8Grey) this.Inputs.CalibMask2;CogImage8Grey imgMask2 (CogImage8Grey) this.Inputs.CalibMask3;CogImage8Grey StitchedImg new CogImage8Grey(Img1.Width500, Img1.Height * 3500);CogImageStitch mStitch new CogImageStitch();// CogImageStitch.FillDefaultWeightImage(StitchedImg);CogImage8Grey imgWeight0 new CogImage8Grey(Img1.Width, Img1.Height);CogImageStitch.FillDefaultWeightImage(imgWeight0);CogImage8Grey imgWeight1 new CogImage8Grey(Img2.Width, Img2.Height);CogImageStitch.FillDefaultWeightImage(imgWeight1);CogImage8Grey imgWeight2 new CogImage8Grey(Img3.Width, Img3.Height);CogImageStitch.FillDefaultWeightImage(imgWeight2);CogTransform2DLinear trans new CogTransform2DLinear();trans.Scaling this.Inputs.dScale;trans.TranslationX this.Inputs.dTransX;trans.TranslationY this.Inputs.dTransY;mStitch.AllocateBlendingBuffer(Img1.Width500, Img1.Height * 3500, trans);mStitch.BlendImageIntoBuffer(Img1, imgWeight0,imgMask0,0,0);mStitch.BlendImageIntoBuffer(Img2,imgWeight1,imgMask1,0,0);mStitch.BlendImageIntoBuffer(Img3,imgWeight2,imgMask2,0,0); mStitch.FillDestinationImageFromBuffer(StitchedImg);// MessageBox.Show(mTrans3.TranslationX.ToString() mTrans3.TranslationY.ToString());this.Tools.CogBlobTool1.InputImage StitchedImg;this.Tools.CogBlobTool1.Run();return false;}总结 1.小视野多次取像每张图片单独使用检测工具精度可满足需求 不够直观调试复杂 2.小视野多次取像根据标定结果进行图像拼接 精度可满足需求同时更加直观客户接受度高检测工具使用更加方便后期维护及设备复制更省心