public ConvertToWriteableBitmap() { WriteableBitmap wb = null; // OpenCVによる画像処理 (Threshold) using (IplImage src = new IplImage(Const.ImageLenna, LoadMode.GrayScale)) using (IplImage dst = new IplImage(src.Size, BitDepth.U8, 1)) { src.Smooth(src, SmoothType.Gaussian, 5); src.Threshold(dst, 0, 255, ThresholdType.Otsu); // IplImage -> WriteableBitmap wb = dst.ToWriteableBitmap(PixelFormats.BlackWhite); //wb = WriteableBitmapConverter.ToWriteableBitmap(dst, PixelFormats.BlackWhite); } // WPFのWindowに表示してみる Image image = new Image { Source = wb }; Window window = new Window { Title = "from IplImage to WriteableBitmap", Width = wb.PixelWidth, Height = wb.PixelHeight, Content = image }; Application app = new Application(); app.Run(window); }
public ConvertToBitmapSource() { BitmapSource bs = null; // OpenCVによる画像処理 (Threshold) using (IplImage src = new IplImage(Const.ImageLenna, LoadMode.GrayScale)) using (IplImage dst = new IplImage(src.Size, BitDepth.U8, 1)) { src.Smooth(src, SmoothType.Gaussian, 5); src.Threshold(dst, 0, 255, ThresholdType.Otsu); // IplImage -> BitmapSource bs = dst.ToBitmapSource(); //bs = BitmapSourceConverter.ToBitmapSource(dst); } // WPFのWindowに表示してみる Image image = new Image { Source = bs }; Window window = new Window { Title = "from IplImage to BitmapSource", Width = bs.PixelWidth, Height = bs.PixelHeight, Content = image }; Application app = new Application(); app.Run(window); }
public ConvertToWriteableBitmap() { WriteableBitmap wb = null; // OpenCV processing using (var src = new IplImage(FilePath.Image.Lenna, LoadMode.GrayScale)) using (var dst = new IplImage(src.Size, BitDepth.U8, 1)) { src.Smooth(src, SmoothType.Gaussian, 5); src.Threshold(dst, 0, 255, ThresholdType.Otsu); // IplImage -> WriteableBitmap wb = dst.ToWriteableBitmap(PixelFormats.BlackWhite); //wb = WriteableBitmapConverter.ToWriteableBitmap(dst, PixelFormats.BlackWhite); } // Shows WriteableBitmap to WPF window var image = new Image { Source = wb }; var window = new Window { Title = "from IplImage to WriteableBitmap", Width = wb.PixelWidth, Height = wb.PixelHeight, Content = image }; var app = new Application(); app.Run(window); }
public ConvertToBitmap() { Bitmap bitmap = null; // do cvThreshold using (IplImage src = new IplImage(FilePath.Image.Lenna, LoadMode.GrayScale)) using (IplImage dst = new IplImage(src.Size, BitDepth.U8, 1)) { src.Smooth(src, SmoothType.Gaussian, 5); src.Threshold(dst, 0, 255, ThresholdType.Otsu); // IplImage -> Bitmap bitmap = dst.ToBitmap(); //bitmap = BitmapConverter.ToBitmap(dst); } // visualize using WindowsForm Form form = new Form { Text = "from IplImage to Bitmap", ClientSize = bitmap.Size, }; PictureBox pictureBox = new PictureBox { Dock = DockStyle.Fill, SizeMode = PictureBoxSizeMode.StretchImage, Image = bitmap }; form.Controls.Add(pictureBox); form.ShowDialog(); form.Dispose(); bitmap.Dispose(); }
public Threshold() { using (IplImage src = new IplImage(Const.ImageLenna, LoadMode.Color)) using (IplImage srcGray = new IplImage(src.Size, BitDepth.U8, 1)) using (IplImage dst = new IplImage(src.Size, BitDepth.U8, 1)) using (CvWindow window = new CvWindow("SampleThreshold")) { src.CvtColor(srcGray, ColorConversion.BgrToGray); srcGray.Smooth(srcGray, SmoothType.Gaussian, 5); int threshold = 90; window.CreateTrackbar("threshold", threshold, 255, delegate(int pos) { srcGray.Threshold(dst, pos, 255, ThresholdType.Binary); window.Image = dst; }); srcGray.Threshold(dst, threshold, 255, ThresholdType.Binary); window.Image = dst; CvWindow.WaitKey(); } }
public ConvertToBitmap() { Bitmap bitmap = null; // OpenCVによる画像処理 (Threshold) using (IplImage src = new IplImage(Const.ImageLenna, LoadMode.GrayScale)) using (IplImage dst = new IplImage(src.Size, BitDepth.U8, 1)) { src.Smooth(src, SmoothType.Gaussian, 5); src.Threshold(dst, 0, 255, ThresholdType.Otsu); // IplImage -> Bitmap bitmap = dst.ToBitmap(); //bitmap = BitmapConverter.ToBitmap(dst); } // WindowsFormに表示してみる Form form = new Form { Text = "from IplImage to Bitmap", ClientSize = bitmap.Size, }; PictureBox pictureBox = new PictureBox { Dock = DockStyle.Fill, SizeMode = PictureBoxSizeMode.StretchImage, Image = bitmap }; /* Imageプロパティに設定するのはもしかするとちょっと微妙、できればこのように pictureBox.Paint += delegate(object sender, PaintEventArgs e) { e.Graphics.DrawImage(bitmap, new Rectangle(new Point(0, 0), form.ClientSize)); }; */ form.Controls.Add(pictureBox); form.ShowDialog(); form.Dispose(); bitmap.Dispose(); }