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 MKeyPoint[] DetectKeyPoints(IInputArray input) { var cudaORB = CreateDetector(); var mat = input as Mat; Image <Gray, byte> image = new Image <Gray, byte>(mat.Bitmap); MKeyPoint[] result; GpuMat gpumat = new GpuMat(image); result = cudaORB.Detect(gpumat); gpumat.Dispose(); cudaORB.Dispose(); return(result); }
public void Match(IInputArray queryDescriptors, IInputArray trainDescriptors, VectorOfVectorOfDMatch matches) { Monitor.Enter(locker); WindowsFormHelper.AddLogToConsole("In monitor"); var _cudaBruteForceMatcher = CreateMatcher(); var left = new GpuMat(queryDescriptors as Mat); var right = new GpuMat(trainDescriptors as Mat); _cudaBruteForceMatcher.KnnMatch(right, left, matches, 1); left.Dispose(); right.Dispose(); _cudaBruteForceMatcher.Dispose(); WindowsFormHelper.AddLogToConsole("Exit monitor"); Monitor.Exit(locker); }
public Mat ComputeDescriptor(KeyPointModel keyPoints) { var cudaORB = CreateDetector(); var mat = new Mat(keyPoints.InputFile.fileInfo.FullName); Image <Gray, byte> image = new Image <Gray, byte>(mat.Bitmap); GpuMat gpumat = new GpuMat(image); GpuMat result = new GpuMat(); cudaORB.Compute(gpumat, keyPoints.DetectedKeyPoints, result); var returnResult = result.ToMat(); gpumat.Dispose(); result.Dispose(); cudaORB.Dispose(); return(returnResult); }
public object[] PerformRotationCompareCuda(double angulo, double scalex, double scaley, int tx, int ty, double skX = 0, double skY = 0) { Image <Rgba, byte> two = null; Image <Rgba, byte> one = null; GpuMat resultMat = new GpuMat(); GpuMat destiny = null; GpuMat compare = null; object[] array = null; GpuMat sumaImg = new GpuMat(); try { // tx += imgUtil.TX/2; //make one from all tranformations // one = imgUtil.expandedOne[0]; one = UIOne; double raidus; int newWidth = Convert.ToInt32(UIOne.Width * scalex); int newHeight = Convert.ToInt32(UIOne.Height * scaley); GpuMat gOne = new GpuMat(one.Mat); GpuMat gNew = new GpuMat(); CudaInvoke.Rotate(gOne, gNew, gOne.Size, angulo, tx, ty); gOne.Dispose(); gOne = new GpuMat(); CudaInvoke.Resize(gNew, gOne, new Size(newWidth, newHeight)); // one = one.Rotate(angulo, imgUtil.pitchBlack).Resize(newWidth, newHeight, Emgu.CV.CvEnum.Inter.Cubic); one = gOne.ToMat().ToImage <Rgba, byte>(); //gNew.Dispose(); // gOne.Dispose(); if (skX != 0 && skY != 0) { //comparison int rows = one.Rows; int cols = one.Cols; int maxXOffset = Convert.ToInt32(Math.Abs(cols * skX)); int maxYOffset = Convert.ToInt32(Math.Abs(rows * skY)); CudaImage <Rgba, byte> sheared = new CudaImage <Rgba, byte>(rows + maxYOffset, cols + maxXOffset, true); try { for (int r = 0; r < sheared.Bitmap.Height; r++) { for (int c = 0; c < sheared.Bitmap.Width; c++) { int newR = r + Convert.ToInt32(c * skY) - maxYOffset / 2; int newC = c + Convert.ToInt32(r * skX) - maxXOffset / 2; if (newR >= 0 && newR < rows && newC >= 0 && newC < cols) { sheared.Bitmap.SetPixel(r, c, one.Bitmap.GetPixel(newR, newC)); } } } } catch (Exception ex) { } // one.Dispose(); one.Dispose(); one = sheared.ToMat().ToImage <Rgba, byte>(); sheared.Dispose(); } // ty += imgUtil.TY/2; // MakeCanvas(ref one, out raidus); // int newWidth = Convert.ToInt32(imgUtil.expandedOne[0].Width*scalex); // int newHeight = Convert.ToInt32(imgUtil.expandedOne[0].Height*scaley); // int newWidth = Convert.ToInt32(UIOne.Width * scalex); // int newHeight = Convert.ToInt32(UIOne.Height * scaley); // int newWidth = Convert.ToInt32(one.Width * scalex); // int newHeight = Convert.ToInt32(one.Height * scaley); // CvInvoke.MinAreaRect(UITwo.Bitmap.GetBounds().) // int area = (UITwo).Height * (UITwo).Width; // area/=3; // int area = Convert.ToInt32( 4e5); //determine bigger between one and two Image <Rgba, byte>[] biggerSmaller = GetBiggerSmallerImages(ref UITwo, ref one); //make canvas from bigger and copy the smaller into this canvas //int area = (biggerSmaller[0]).Height * (biggerSmaller[0]).Width; two = MakeCanvas(ref biggerSmaller[0], out raidus); ///CAMBIE ESTO Point middle = GetMiddlePointCanvas(raidus, ref biggerSmaller[1]); // middle.X += tx; // middle.Y += ty; ///////////// // Point middle = GetMiddlePointCanvas(raidus, ref biggerSmaller[0]); Copy(ref middle, ref two, ref biggerSmaller[1]); //get Mat destiny = new GpuMat(two.Mat); two = two.CopyBlank(); // two.Dispose(); //make canvas from bigger again // two = MakeCanvas(ref biggerSmaller[0], out raidus);//;.Width, expandedEscaledUIToCompare[1].Height, pitchWhite); // Copy the bigger into the canvas middle = GetMiddlePointCanvas(raidus, ref biggerSmaller[0]); Copy(ref middle, ref two, ref biggerSmaller[0]); compare = new GpuMat(two.Mat); //two.Mat.Clone(); two.Dispose(); object result = null; CudaInvoke.BitwiseXor(compare, destiny, resultMat, null);// Emgu.CV.CvEnum.CmpType.Equal); // CudaInvoke.Subtract(compare, destiny, resultMat); // CudaInvoke.Pow(resultMat, 2, resultMat); // CvInvoke.Compare(compare, destiny, resultMat, Emgu.CV.CvEnum.CmpType.Equal); CudaInvoke.Add(compare, destiny, sumaImg);//.ass.ToImage<Rgba,byte>().Add(destiny.ToImage<Rgba,byte>()).Mat; result = resultMat.ToMat(); two = resultMat.ToMat().ToImage <Rgba, byte>(); object suma = null; object count = null; suma = two.GetSum(); count = two.CountNonzero(); int area = Convert.ToInt32(2e5); (count as int[])[3] = area; // result = two.Mat.Clone(); // CvInvoke.Subtract(compare, destiny, resultMat); array = new object[] { result, count, suma }; } catch (Exception ex) { } destiny?.Dispose(); compare?.Dispose(); resultMat?.Dispose(); two?.Dispose(); one?.Dispose(); sumaImg?.Dispose(); return(array); }