Esempio n. 1
0
        public void CalcuateMeanshift(Image <Bgra, byte> imgInput, int spatialWindow = 5, int colorWindow = 5, int MinSegmentSize = 20)
        {
            if (imgInput == null)
            {
                return;
            }
            try
            {
                Image <Bgra, byte> imgOutput = new Image <Bgra, byte>(imgInput.Width, imgInput.Height, new Bgra(0, 0, 0, 0));

                //convert the image to BGRA as it requires a BGRA to pass it in constructor of CudaImage
                CudaImage <Bgra, byte> _inputCuda = new CudaImage <Bgra, byte>(imgInput);
                CudaInvoke.MeanShiftSegmentation(_inputCuda, imgOutput, spatialWindow, colorWindow, MinSegmentSize, new MCvTermCriteria(1, .001));
                pictureBox2.Image = imgOutput.Bitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Meam shift error: " + ex.Message);
            }
        }
Esempio n. 2
0
        public static Image <Emgu.CV.Structure.Bgr, Byte> MeanShiftEmguCVCuda(Image <Bgr, Byte> image)
        {
            if (CudaInvoke.HasCuda == false)
            {
                throw new Exception("OpenCV: The library is compiled without CUDA support");
            }

            Image <Bgra, byte> imgInput  = new Image <Bgra, byte>(image.Bitmap);
            Image <Bgra, byte> imgOutput = new Image <Bgra, byte>(imgInput.Size);

            CudaImage <Bgra, byte> cudaImage = new CudaImage <Bgra, byte>(imgInput);

            int sp       = 5;
            int sr       = 10;
            int minsize  = 50;
            int criteria = 10; //No. iteration

            CudaInvoke.MeanShiftSegmentation(cudaImage, imgOutput, sp, sr, minsize, new MCvTermCriteria(criteria));

            Image <Bgr, byte> result = new Image <Bgr, byte>(imgOutput.Bitmap);

            return(result);
        }