public void TestCudaSURFKeypointDetection() { if (CudaInvoke.HasCuda) { Image <Gray, byte> image = new Image <Gray, byte>(200, 100); image.SetRandUniform(new MCvScalar(), new MCvScalar(255)); GpuMat gpuMat = new GpuMat(image); EmguAssert.IsTrue(gpuMat.ToMat().Equals(image.Mat)); CudaSURF cudaSurf = new CudaSURF(100.0f, 2, 4, false, 0.01f, false); GpuMat cudaKpts = cudaSurf.DetectKeyPointsRaw(gpuMat, null); VectorOfKeyPoint kpts = new VectorOfKeyPoint(); cudaSurf.DownloadKeypoints(cudaKpts, kpts); } }
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 void TestErodeDilate() { if (!CudaInvoke.HasCuda) { return; } int morphIter = 2; Image <Gray, Byte> image = new Image <Gray, byte>(640, 320); image.Draw(new CircleF(new PointF(200, 200), 30), new Gray(255.0), 4); Size ksize = new Size(morphIter * 2 + 1, morphIter * 2 + 1); using (GpuMat cudaImage = new GpuMat(image)) using (GpuMat cudaTemp = new GpuMat()) using (Stream stream = new Stream()) using (CudaBoxMaxFilter dilate = new CudaBoxMaxFilter(DepthType.Cv8U, 1, ksize, new Point(-1, -1), CvEnum.BorderType.Default, new MCvScalar())) using (CudaBoxMinFilter erode = new CudaBoxMinFilter(DepthType.Cv8U, 1, ksize, new Point(-1, -1), CvEnum.BorderType.Default, new MCvScalar())) { //run the GPU version asyncrhonously with stream erode.Apply(cudaImage, cudaTemp, stream); dilate.Apply(cudaTemp, cudaImage, stream); //run the CPU version in parallel to the gpu version. using (Image <Gray, Byte> temp = new Image <Gray, byte>(image.Size)) { CvInvoke.Erode(image, temp, null, new Point(-1, -1), morphIter, CvEnum.BorderType.Constant, new MCvScalar()); CvInvoke.Dilate(temp, image, null, new Point(-1, -1), morphIter, CvEnum.BorderType.Constant, new MCvScalar()); } //syncrhonize with the GPU version stream.WaitForCompletion(); Assert.IsTrue(cudaImage.ToMat().Equals(image.Mat)); } }
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); }
public void TestCudaSURFKeypointDetection() { if (CudaInvoke.HasCuda) { Image<Gray, byte> image = new Image<Gray, byte>(200, 100); image.SetRandUniform(new MCvScalar(), new MCvScalar(255)); GpuMat gpuMat = new GpuMat(image); EmguAssert.IsTrue(gpuMat.ToMat().Equals(image.Mat)); CudaSURF cudaSurf = new CudaSURF(100.0f, 2, 4, false, 0.01f, false); GpuMat cudaKpts = cudaSurf.DetectKeyPointsRaw(gpuMat, null); VectorOfKeyPoint kpts = new VectorOfKeyPoint(); cudaSurf.DownloadKeypoints(cudaKpts, kpts); } }
public void TestErodeDilate() { if (!CudaInvoke.HasCuda) return; int morphIter = 2; Image<Gray, Byte> image = new Image<Gray, byte>(640, 320); image.Draw(new CircleF(new PointF(200, 200), 30), new Gray(255.0), 4); Size ksize = new Size(morphIter * 2 + 1, morphIter * 2 + 1); using (GpuMat cudaImage = new GpuMat(image)) using (GpuMat cudaTemp = new GpuMat()) using (Stream stream = new Stream()) using (CudaBoxMaxFilter dilate = new CudaBoxMaxFilter(DepthType.Cv8U, 1, ksize, new Point(-1, -1), CvEnum.BorderType.Default, new MCvScalar())) using (CudaBoxMinFilter erode = new CudaBoxMinFilter(DepthType.Cv8U, 1, ksize, new Point(-1, -1), CvEnum.BorderType.Default, new MCvScalar())) { //run the GPU version asyncrhonously with stream erode.Apply(cudaImage, cudaTemp, stream); dilate.Apply(cudaTemp, cudaImage, stream); //run the CPU version in parallel to the gpu version. using (Image<Gray, Byte> temp = new Image<Gray, byte>(image.Size)) { CvInvoke.Erode(image, temp, null, new Point(-1, -1), morphIter, CvEnum.BorderType.Constant, new MCvScalar()); CvInvoke.Dilate(temp, image, null, new Point(-1, -1), morphIter, CvEnum.BorderType.Constant, new MCvScalar()); } //syncrhonize with the GPU version stream.WaitForCompletion(); Assert.IsTrue(cudaImage.ToMat().Equals(image.Mat)); } }