EMGU CV中的图像位置补偿

时间:2018-09-21 12:06:18

标签: c# image image-processing emgucv

我在项目中遇到了这个障碍。 我有一个包含三个打印对象的图像,我想检查打印过程中对象是否向上或向下移动。如果它超过/超过阈值限制,则需要将其拒绝。

E.G: CLick here for image

上图显示了一个很好的示例,我在所有3个对象周围选择了一个ROI,以减少检查时间。但是问题是,尽管打印效果很好,但是产品在打印过程中还是有些移动,图像的图像在我的投资回报率范围内发生了偏移,并且坐标发生了变化,导致它们被拒绝了。

EG:

CLick here for image

如何使图像相对于中心对象居中(ROI图像)(中心对象在打印过程中永远不会移动)。

我正在使用模板匹配来查找对象,如下所示:

            Image<Bgr, Byte> templateImage = img_tofind;
            Image<Bgr, Byte> sourceImage = ROI_Image;

            using (Image<Gray, float> imgMatch = 
             sourceImage.MatchTemplate(templateImage, 
              Emgu.CV.CvEnum.TM_TYPE.CV_TM_CCOEFF_NORMED))
            {

                Point[] MAX_Loc, Min_Loc;
                double[] min, max;
                imgMatch.MinMax(out min, out max, out Min_Loc, out 
                 MAX_Loc);

                using (Image<Gray, double> RG_Image = 
                imgMatch.Convert<Gray, double>().Copy())
                {
                  if (max[0] > 0.60)
                    {
                        Rectangle match = new Rectangle(MAX_Loc[0], 
                        templateImage.Size);
                        sourceImage.Draw(match, new Bgr(Color.Red), 1);

                        int hw = match.Width;
                        int hh = match.Height;
                        int htlx = match.X;
                        int htly = match.Y;

                        hres1 = htlx + hw / 2; Object COG X
                        hres2 = htly + hh / 2;  Object COG Y

                    }

                }
                ibresult.Image = sourceImage;
            }

我希望ROI图像始终相对于中心对象居中。

0 个答案:

没有答案