コード例 #1
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return(-1);
            }

            CvSmoothType valueCvSmoothType = (CvSmoothType)value;

            switch (valueCvSmoothType)
            {
            case CvSmoothType.BLUR:
                return(0);

            case CvSmoothType.BLUR_NO_SCALE:
                return(1);

            case CvSmoothType.MEDIAN:
                return(2);

            case CvSmoothType.GAUSSIAN:
                return(3);

            case CvSmoothType.BILATERAL:
                return(4);

            default:
                return(-1);
            }
        }
コード例 #2
0
        /// <summary>
        /// 平滑化
        /// </summary>
        private void CreateSmoothImage()
        {
            try
            {
                if (this.FileName == null)
                {
                    this.FileName = this.SelectImageFile();
                }

                CvSmoothType smoothType = this.SmoothProperty.SmoothType;
                int          filterX    = this.SmoothProperty.FilterX;
                int          filterY    = this.SmoothProperty.FilterY;
                double       sigma1     = this.SmoothProperty.Sigma1;
                double       sigma2     = this.SmoothProperty.Sigma2;

                using (CvImage orgImage = new CvImage(this.FileName))
                    using (CvImage smoothImage = CvImgProc.Smooth(orgImage, smoothType, filterX, filterY, sigma1, sigma2))
                        using (MemoryStream stream = new MemoryStream())
                        {
                            Bitmap bitmap = smoothImage.GetImageBmp();

                            if (bitmap == null)
                            {
                                MessageBox.Show("bitmap null.");
                                return;
                            }

                            bitmap.Save(stream, ImageFormat.Bmp);

                            // BitmapImageの作成(キャッシュを切る)
                            BitmapImage bmpImage = new BitmapImage();
                            bmpImage.BeginInit();
                            bmpImage.CacheOption   = BitmapCacheOption.OnLoad;
                            bmpImage.CreateOptions = BitmapCreateOptions.None;
                            bmpImage.StreamSource  = stream;
                            bmpImage.EndInit();
                            bmpImage.Freeze();

                            this.Image006.Source = bmpImage;

                            bmpImage = null;
                        }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }