【问题标题】:C# - WPF/Xaml - EMGU Display imageC# - WPF/Xaml - EMGU 显示图像
【发布时间】:2021-04-13 02:50:11
【问题描述】:

我有一个 C#/WPF 程序,它使用 EMGU 来处理 4K 视频(每个图像的图像)。我正在对图像进行一些操作,例如旋转、裁剪……这些操作很快。

我的问题是显示图像需要很长时间(40 毫秒)。如果我将我的操作添加到这个时间,我的速度将低于 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));

你知道显示我的图像的最快方法吗?

谢谢,

【问题讨论】:

    标签: c# emgucv


    【解决方案1】:

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

    1. 我创建了可写位图
    2. 我基于可写位图缓冲区创建 EMGU 图像

    然后在我的过程中我有:

    1. 获取灰度图
    2. 直接在EMGU Image中转换灰度图
    3. 告诉可写位图缓冲区已更新

    分配变量:

                 _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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      相关资源
      最近更新 更多