[英]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));
你知道顯示我的圖像的最快方法嗎?
謝謝,
好的,我找到了完美的解決方案。
然后在我的過程中,我有:
分配變量:
_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.