public PlayerBossPos GetPlayerAndBossLocation() { PlayerBossPos ret = new PlayerBossPos(); GrabImage(548, 82, 730, 706); Mat temp = new Mat(imgGrab.ToMat(), new Rectangle(0, 0, 730, 706)); GpuMat result = new GpuMat(temp); GpuMat output = new GpuMat(temp); temp.Dispose(); ctm.Match(result, playerimg, output); double minval = 0, maxval = 0; Point maxloc = new Point(), minloc = new Point(); CudaInvoke.MinMaxLoc(output, ref minval, ref maxval, ref minloc, ref maxloc); ctm.Match(result, bossimg, output); double minvalb = 0, maxvalb = 0; Point maxlocb = new Point(), minlocb = new Point(); CudaInvoke.MinMaxLoc(output, ref minvalb, ref maxvalb, ref minlocb, ref maxlocb); ret.px = maxloc.X; ret.py = maxloc.Y; ret.bx = maxlocb.X; ret.by = maxlocb.Y; result.Dispose(); output.Dispose(); return(ret); }
public void TestMatchTemplate() { if (!CudaInvoke.HasCuda) { return; } #region prepare synthetic image for testing int templWidth = 50; int templHeight = 50; Point templCenter = new Point(120, 100); //Create a random object Image <Bgr, Byte> randomObj = new Image <Bgr, byte>(templWidth, templHeight); randomObj.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255)); //Draw the object in image1 center at templCenter; Image <Bgr, Byte> img = new Image <Bgr, byte>(300, 200); Rectangle objectLocation = new Rectangle(templCenter.X - (templWidth >> 1), templCenter.Y - (templHeight >> 1), templWidth, templHeight); img.ROI = objectLocation; randomObj.Copy(img, null); img.ROI = Rectangle.Empty; #endregion Image <Gray, Single> match = img.MatchTemplate(randomObj, Emgu.CV.CvEnum.TemplateMatchingType.Sqdiff); double[] minVal, maxVal; Point[] minLoc, maxLoc; match.MinMax(out minVal, out maxVal, out minLoc, out maxLoc); double gpuMinVal = 0, gpuMaxVal = 0; Point gpuMinLoc = Point.Empty, gpuMaxLoc = Point.Empty; GpuMat cudaImage = new GpuMat(img); GpuMat gpuRandomObj = new GpuMat(randomObj); GpuMat gpuMatch = new GpuMat(); using (CudaTemplateMatching buffer = new CudaTemplateMatching(DepthType.Cv8U, 3, CvEnum.TemplateMatchingType.Sqdiff)) using (Stream stream = new Stream()) { buffer.Match(cudaImage, gpuRandomObj, gpuMatch, stream); //GpuInvoke.MatchTemplate(CudaImage, gpuRandomObj, gpuMatch, CvEnum.TM_TYPE.CV_TM_SQDIFF, buffer, stream); stream.WaitForCompletion(); CudaInvoke.MinMaxLoc(gpuMatch, ref gpuMinVal, ref gpuMaxVal, ref gpuMinLoc, ref gpuMaxLoc, null); } EmguAssert.AreEqual(minLoc[0].X, templCenter.X - templWidth / 2); EmguAssert.AreEqual(minLoc[0].Y, templCenter.Y - templHeight / 2); EmguAssert.IsTrue(minLoc[0].Equals(gpuMinLoc)); EmguAssert.IsTrue(maxLoc[0].Equals(gpuMaxLoc)); }
public bool OnFire() { ms2.GrabImage(690, 816, 170, 29); Mat temp = new Mat(ms2.imgGrab.ToMat(), new Rectangle(0, 0, 170, 29)); GpuMat result = new GpuMat(temp); GpuMat output = new GpuMat(temp); temp.Dispose(); ms2.ctm.Match(result, fireimg, output); double minval = 0, maxval = 0; Point maxloc = new Point(), minloc = new Point(); CudaInvoke.MinMaxLoc(output, ref minval, ref maxval, ref minloc, ref maxloc); if (maxval > .9f) { return(true); } return(false); }