static void Main(string[] args) { Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";runtimes/win10-x64/"); //only needed if projects are directly referenced var img = new Bgr <byte> [480, 640]; //*********************************************************************************************************************************************************************** Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("********* TColor[,] <=> Image<> conversions (built-in) ****************"); Console.ResetColor(); //to Image<> Image <Bgr <byte> > lockedImg = img.Lock(); //from Image<> var arr = lockedImg.Clone(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("********* Image<,> <=> OpenCV conversions (built-in) ****************"); Console.ResetColor(); //to IplImage IplImage iplImage; using (var uImg = img.Lock()) { iplImage = uImg.AsCvIplImage(); //data is shared } //from IplImage var imgFromIpl = iplImage.AsImage(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("*********** Image<,> <=> Bitmap conversions (BitmapInterop) ****************"); Console.ResetColor(); //to Bitmap var bmp = img.ToBitmap(); //from Bitmap var imgFromBmp = bmp.ToImage <Bgr <byte> >(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("*********** Image<,> <=> BitmapSource conversions (BitmapSourceInterop) ****************"); Console.ResetColor(); //to generic-image var colorBitmap = new BitmapImage(new Uri("http://www.online-image-editor.com//styles/2014/images/example_image.png")); Bgra <byte>[,] colorImg = colorBitmap.ToArray <Bgra <byte> >(); //to BitmapSource Gray <byte>[,] grayImg = img.ToGray(); BitmapSource grayBitmap = grayImg.ToBitmapSource(); }
static void Main(string[] args) { var img = new Bgr <byte> [480, 640]; //*********************************************************************************************************************************************************************** Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* TColor[,] <=> Image<> conversions (built-in) ****************"); Console.ResetColor(); //to Image<> Image <Bgr <byte> > lockedImg = img.Lock(); //from Image<> var arr = lockedImg.Clone(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********* Image<,> <=> OpenCV conversions (built-in) ****************"); Console.ResetColor(); //to IplImage IplImage iplImage; using (var uImg = img.Lock()) { iplImage = uImg.AsCvIplImage(); //data is shared } //from IplImage var imgFromIpl = iplImage.AsImage(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("*********** Image<,> <=> Bitmap conversions (BitmapInterop) ****************"); Console.ResetColor(); //to Bitmap var bmp = img.ToBitmap(); //from Bitmap var imgFromBmp = bmp.ToArray(); //*********************************************************************************************************************************************************************** Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("*********** Image<,> <=> BitmapSource conversions (BitmapSourceInterop) ****************"); Console.ResetColor(); //to generic-image var colorBitmap = new BitmapImage(new Uri("http://www.online-image-editor.com//styles/2014/images/example_image.png")); Bgra <byte>[,] colorImg = colorBitmap.ToArray <Bgra <byte> >(); //to BitmapSource Gray <byte>[,] grayImg = img.ToGray(); BitmapSource grayBitmap = grayImg.ToBitmapSource(); }