private void CreateImageForTracking(WriteableBitmap bitmap, byte[] pixels)
 {
     try
     {
         convertedImage   = ImageHelpers.BitmapToFormat(bitmap, PixelFormats.Bgr32);
         openCVImg        = new Image <Bgr, byte>(convertedImage.GetBitmap());
         thresholdedImage = openCVImg.Convert <Gray, byte>().ThresholdBinary(new Gray(thresholdValue.Value),
                                                                             new Gray(255));
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed to create Emgu images");
         Console.WriteLine(ex);
     }
 }
Ejemplo n.º 2
0
 public static AuxiliaryLibraries.Media.Bitmap GetBitmap(this BitmapSource bitmapSource)
 {
     AuxiliaryLibraries.Media.PixelFormat pix = WPFToAux(bitmapSource.Format);
     if (pix != AuxiliaryLibraries.Media.PixelFormats.Undefined)
     {
         var colors = bitmapSource.Palette?.Colors.Select(x => System.Drawing.Color.FromArgb(x.A, x.R, x.G, x.B)).ToArray();
         return(new AuxiliaryLibraries.Media.Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight,
                                                    pix, bitmapSource.GetData(), colors));
     }
     else
     {
         FormatConvertedBitmap formatConvertedBitmap = new FormatConvertedBitmap(bitmapSource, PixelFormats.Bgra32, null, 0);
         return(formatConvertedBitmap.GetBitmap());
     }
 }