/// <summary> /// Convert the CudaImage to its equivalent Bitmap representation /// </summary> public static Bitmap ToBitmap <TColor, TDepth>(this CudaImage <TColor, TDepth> cudaImage) where TColor : struct, IColor where TDepth : new() { if (typeof(TColor) == typeof(Bgr) && typeof(TDepth) == typeof(Byte)) { Size s = cudaImage.Size; Bitmap result = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData data = result.LockBits(new Rectangle(Point.Empty, result.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, result.PixelFormat); using (Image <TColor, TDepth> tmp = new Image <TColor, TDepth>(s.Width, s.Height, data.Stride, data.Scan0) ) { cudaImage.Download(tmp); } result.UnlockBits(data); return(result); } else { using (Image <TColor, TDepth> tmp = cudaImage.ToImage()) { return(tmp.ToBitmap()); } } }
public void TestClahe() { if (CudaInvoke.HasCuda) { Image <Gray, Byte> image = EmguAssert.LoadImage <Gray, Byte>("pedestrian.png"); CudaImage <Gray, Byte> cudaImage = new CudaImage <Gray, byte>(image); CudaImage <Gray, Byte> cudaResult = new CudaImage <Gray, byte>(cudaImage.Size); using (CudaClahe clahe = new CudaClahe(40.0, new Size(8, 8))) { Image <Gray, Byte> result = new Image <Gray, byte>(cudaResult.Size); clahe.Apply(cudaImage, cudaResult, null); cudaResult.Download(result); //Emgu.CV.UI.ImageViewer.Show(image.ConcateHorizontal(result)); } } }
public void TestCudaFlip() { if (CudaInvoke.HasCuda) { using (Image <Bgr, Byte> img1 = new Image <Bgr, byte>(1200, 640)) { img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255)); using (Image <Bgr, Byte> img1Flip = img1.Flip(CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical)) using (CudaImage <Bgr, Byte> cudaImage = new CudaImage <Bgr, byte>(img1)) using (CudaImage <Bgr, Byte> cudaFlip = new CudaImage <Bgr, byte>(img1.Size)) { CudaInvoke.Flip(cudaImage, cudaFlip, CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical, null); cudaFlip.Download(img1); Assert.IsTrue(img1.Equals(img1Flip)); } } } }
public void TestCudaPyrLKOpticalFlow() { if (!CudaInvoke.HasCuda) { return; } Image <Gray, Byte> prevImg, currImg; AutoTestVarious.OpticalFlowImage(out prevImg, out currImg); Image <Gray, Single> flowx = new Image <Gray, float>(prevImg.Size); Image <Gray, Single> flowy = new Image <Gray, float>(prevImg.Size); CudaPyrLKOpticalFlow flow = new CudaPyrLKOpticalFlow(new Size(21, 21), 3, 30, false); using (CudaImage <Gray, Byte> prevGpu = new CudaImage <Gray, byte>(prevImg)) using (CudaImage <Gray, byte> currGpu = new CudaImage <Gray, byte>(currImg)) using (CudaImage <Gray, float> flowxGpu = new CudaImage <Gray, float>(prevGpu.Size)) using (CudaImage <Gray, float> flowyGpu = new CudaImage <Gray, float>(prevGpu.Size)) { flow.Dense(prevGpu, currGpu, flowxGpu, flowyGpu); flowxGpu.Download(flowx); flowyGpu.Download(flowy); } }
public void TestClahe() { if (CudaInvoke.HasCuda) { Image<Gray, Byte> image = EmguAssert.LoadImage<Gray, Byte>("pedestrian.png"); CudaImage<Gray, Byte> cudaImage = new CudaImage<Gray, byte>(image); CudaImage<Gray, Byte> cudaResult = new CudaImage<Gray, byte>(cudaImage.Size); using (CudaClahe clahe = new CudaClahe(40.0, new Size(8, 8))) { Image<Gray, Byte> result = new Image<Gray, byte>(cudaResult.Size); clahe.Apply(cudaImage, cudaResult, null); cudaResult.Download(result); //Emgu.CV.UI.ImageViewer.Show(image.ConcateHorizontal(result)); } } }
public void TestCudaFlip() { if (CudaInvoke.HasCuda) { using (Image<Bgr, Byte> img1 = new Image<Bgr, byte>(1200, 640)) { img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255)); using (Image<Bgr, Byte> img1Flip = img1.Flip(CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical)) using (CudaImage<Bgr, Byte> cudaImage = new CudaImage<Bgr, byte>(img1)) using (CudaImage<Bgr, Byte> cudaFlip = new CudaImage<Bgr,byte>(img1.Size)) { CudaInvoke.Flip(cudaImage, cudaFlip, CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical, null); cudaFlip.Download(img1); Assert.IsTrue(img1.Equals(img1Flip)); } } } }