Пример #1
0
      public void TestCudaImageAsyncOps()
      {
         if (CudaInvoke.HasCuda)
         {
            int counter = 0;
            Stopwatch watch = Stopwatch.StartNew();
            using (GpuMat img1 = new GpuMat(3000, 2000, DepthType.Cv8U, 3))
            using (GpuMat img2 = new GpuMat(3000, 2000, DepthType.Cv8U, 3))
            using (GpuMat img3 = new GpuMat())
            using (Stream stream = new Stream())
            using (GpuMat mat1 = new GpuMat())
            {
               img1.ConvertTo(mat1, DepthType.Cv8U, 1, 0, stream);
               while (!stream.Completed)
               {
                  if (counter <= int.MaxValue) counter++;
               }
               Trace.WriteLine(String.Format("Counter has been incremented {0} times", counter));

               counter = 0;
               CudaInvoke.CvtColor(img2, img3, CvToolbox.GetColorCvtCode(typeof(Bgr), typeof(Gray)), 1, stream);
               while (!stream.Completed)
               {
                  if (counter <= int.MaxValue) counter++;
               }
               Trace.WriteLine(String.Format("Counter has been incremented {0} times", counter));
            }
            watch.Stop();
            Trace.WriteLine(String.Format("Total time: {0} milliseconds", watch.ElapsedMilliseconds));
         }
      }
        public override Mat ComputeDepthMap(Image <Bgr, byte> leftImage, Image <Bgr, byte> rightImage)
        {
            CudaStereoBM _cudaStereoBM = CreateCudaStereoBM();

            ConvertImageToGray(leftImage, rightImage);

            GpuMat            imageDisparity  = new GpuMat();
            GpuMat            imageToSave     = new GpuMat();
            Image <Bgr, byte> disparityToSave = new Image <Bgr, byte>(leftImage.Size);
            Mat disparity = new Mat();

            _cudaStereoBM.FindStereoCorrespondence(LeftGrayImage.ImageToGpuMat(), RightGrayImage.ImageToGpuMat(), imageDisparity);

            imageDisparity.ConvertTo(imageToSave, DepthType.Cv8U);
            imageToSave.Download(disparityToSave);
            imageDisparity.Download(disparity);

            return(disparity);
        }
Пример #3
0
        public ImageRenderEngineGpu(IConsoleDisplayInfo consoleDisplayInfo) :
            base(consoleDisplayInfo)
        {
            var charMat = new Dictionary <string, GpuMat>();

            using (var tmp = new GpuMat())
                using (var mat = new Mat())
                {
                    foreach (var(c, data) in consoleDisplayInfo.PrintableChars)
                    {
                        CvInvoke.Imdecode(data, ImreadModes.Grayscale, mat);
                        tmp.Upload(mat);
                        var gMat = new GpuMat();
                        tmp.ConvertTo(gMat, DepthType.Cv32F);
                        charMat.Add(c, gMat);
                    }
                }
            this.charMats = charMat;
        }
Пример #4
0
        public override string RenderImage(Mat imgMat)
        {
            const DepthType cDepthType = DepthType.Cv32F;

            using (var tmp = new GpuMat())
                using (var gImgMat = new GpuMat())
                    using (var param = new DisposingThreadLocal <MSSIMGpuParam>(
                               () => new MSSIMGpuParam(info.CharPixelSize, cDepthType, channels: imgMat.NumberOfChannels)))
                    {
                        tmp.Upload(imgMat);
                        tmp.ConvertTo(gImgMat, cDepthType);
                        var idx = new List <(int, int)>();
                        for (var y = 0; y < info.HeightInRows; y++)
                        {
                            for (var x = 0; x < info.WidthInColumns; x++)
                            {
                                idx.Add((y, x));
                            }
                        }
                        var charImg = new string[info.HeightInRows, info.WidthInColumns];
                        Parallel.ForEach(idx, ComparePiece);
                        void ComparePiece((int, int) i)
                        {
                            var(y, x) = i;
                            var rowRange = new Range(y * info.CharPixelHeight, (y + 1) * info.CharPixelHeight);
                            var colRange = new Range(x * info.CharPixelWidth, (x + 1) * info.CharPixelWidth);

                            using (var piece = new GpuMat(gImgMat, rowRange, colRange))
                            {
                                var c =
                                    charMats
                                    .MaxBy(kvp => MSSIM.MSSIMGpu(kvp.Value, piece, param.Value))
                                    .Key;
                                charImg[y, x] = c;
                            }
                        }

                        return(string.Concat(charImg));
                    }
        }
Пример #5
0
        public void TestCudaImageAsyncOps()
        {
            if (CudaInvoke.HasCuda)
            {
                int       counter = 0;
                Stopwatch watch   = Stopwatch.StartNew();
                using (GpuMat img1 = new GpuMat(3000, 2000, DepthType.Cv8U, 3))
                    using (GpuMat img2 = new GpuMat(3000, 2000, DepthType.Cv8U, 3))
                        using (GpuMat img3 = new GpuMat())
                            using (Stream stream = new Stream())
                                using (GpuMat mat1 = new GpuMat())
                                {
                                    img1.ConvertTo(mat1, DepthType.Cv8U, 1, 0, stream);
                                    while (!stream.Completed)
                                    {
                                        if (counter <= int.MaxValue)
                                        {
                                            counter++;
                                        }
                                    }
                                    Trace.WriteLine(String.Format("Counter has been incremented {0} times", counter));

                                    counter = 0;
                                    CudaInvoke.CvtColor(img2, img3, CvToolbox.GetColorCvtCode(typeof(Bgr), typeof(Gray)), 1, stream);
                                    while (!stream.Completed)
                                    {
                                        if (counter <= int.MaxValue)
                                        {
                                            counter++;
                                        }
                                    }
                                    Trace.WriteLine(String.Format("Counter has been incremented {0} times", counter));
                                }
                watch.Stop();
                Trace.WriteLine(String.Format("Total time: {0} milliseconds", watch.ElapsedMilliseconds));
            }
        }