Access violation/Program not responding when Matching template from Camera capture. (C

Материал из Wiki Test Lab
Перейти к: навигация, поиск

Назад    Главная
 

Access violation/Program not responding when Matching template from Camera capture. (C# EmguCV).

   private void ProcessFrame(object sender, EventArgs arg)
   {
       Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
       Image<Bgr, Byte> template = new Image<Bgr, byte>(@"D:\yugiCards\kuriboh.jpg");
       Image<Bgr, Byte> imageToShow = ImageFrame.Copy();
       using (Image<Gray, float> result = imageToShow.MatchTemplate(template, Emgu.CV.CvEnum.TM_TYPE.CV_TM_CCOEFF_NORMED))
       {
           double[] minValues, maxValues;
           Point[] minLocations, maxLocations;
           result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
           // You can try different values of the threshold. I guess somewhere between 0.75 and 0.95 would be good.
           if (maxValues[0] > 0.9)
           {
               // This is a match. Do something with it, for example draw a rectangle around it.
               Rectangle match = new Rectangle(maxLocations[0], template.Size);
               imageToShow.Draw(match, new Bgr(Color.Red), 3);
           }
       }
       CamImageBox.Image = imageToShow; 
       //ImageFrame.Save(@"E:\MyPic.jpg");  //saves to location
   }


Личные инструменты