簡體   English   中英

C# - WPF/Xaml - EMGU 顯示圖像

[英]C# - WPF/Xaml - EMGU Display image

我有一個 C#/WPF 程序,它使用 EMGU 來處理 4K 視頻(每個圖像的圖像)。 我正在對圖像進行一些操作,例如旋轉、裁剪……這些操作很快。

我的問題是顯示圖像需要很長時間(40ms)。 如果我將我的操作添加到這個時間,我的速度將低於 20FPS。 顯示圖像的時間占 70%。

我正在使用這段代碼:

<Image x:Name="VideoWidget" Stretch="Uniform"/>

if (_cameraWritableBitmap == null || _cameraWritableBitmap.PixelWidth != width || _cameraWritableBitmap.PixelHeight != height)
{
    _cameraWritableBitmap = new WriteableBitmap(
        width,
        height,
        dpiX,
        dpiY,
        pixelFormat,
        null);

    _mainWindow.VideoWidget.Source = _cameraWritableBitmap;
    OnPropertyChanged("ZoomImage");
    OnPropertyChanged("ZoomScreen");
    OnPropertyChanged("IsZoomImageAlert");
    OnPropertyChanged("IsZoomScreenAlert");
}

timePrev = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

_cameraWritableBitmap.Lock();
_cameraWritableBitmap.WritePixels(new Int32Rect(0, 0, width, height), imgColor.Bytes, width * 4, 0);
//Marshal.Copy(imgColor.Bytes, 0, _cameraWritableBitmap.BackBuffer, imgColor.Bytes.Length);
//_cameraWritableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
_cameraWritableBitmap.Unlock();
Console.WriteLine("# ECRITURE " + (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - timePrev));

你知道顯示我的圖像的最快方法嗎?

謝謝,

好的,我找到了完美的解決方案。

  1. 我創建了可寫的 Bitmap
  2. 我基於可寫 bitmap 緩沖區創建 EMGU 圖像

然后在我的過程中,我有:

  1. 獲取灰度圖像
  2. 直接在EMGU Image中轉換灰度圖
  3. 告訴可寫 bitmap 緩沖區已更新

分配變量:

             _cameraWritableBitmap = new WriteableBitmap(
                width,
                height,
                dpiX,
                dpiY,
                PixelFormats.Bgra32,
                null);

            _mainWindow.VideoWidget.Source = _cameraWritableBitmap;

            _cameraImageBuffer = new Image<Bgra, byte>(width, height, _cameraWritableBitmap.BackBufferStride, _cameraWritableBitmap.BackBuffer);

將灰色轉換為顏色:

CvInvoke.CvtColor(imgGray, _cameraImageBuffer, Emgu.CV.CvEnum.ColorConversion.Gray2Bgra);

更新畫面:

_cameraWritableBitmap.Lock();
_cameraWritableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
_cameraWritableBitmap.Unlock();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM