【问题标题】:Video stream from Windows USB device is upside down using AForge使用 AForge 将来自 Windows USB 设备的视频流颠倒
【发布时间】:2015-09-07 12:50:16
【问题描述】:

我正在使用 AForge.net version 2.25 显示来自 USB 数码显微镜 Celestron 44302-B 的视频馈送。使用显微镜软件,视频在 Windows 7 x64 工作站上正确显示。

代码基于 Aforge 的示例应用程序。结果如下所示,其中 AForge.Controls.videoSourcePlayer 中的视频源是颠倒的。

我可以轻松翻转单个位图(从视频流中截取的快照),但我希望允许用户在连接并运行视频源时定位和聚焦显微镜。

using AForge.Controls
using AForge.Video;
using AForge.Video.DirectShow;

void connectButton_Click(object sender, EventArgs e)
{
      VideoCaptureDevice _videoDevice = new VideoCaptureDevice(_videoDevices[devicesCombo.SelectedIndex].MonikerString);

        if (_videoDevice != null)
        {
            if ((_videoCapabilities != null) && (_videoCapabilities.Length != 0))
            {
                _videoDevice.VideoResolution = _videoCapabilities[videoResolutionsCombo.SelectedIndex];
            }

            if ((_snapshotCapabilities != null) && (_snapshotCapabilities.Length != 0))
            {
                _videoDevice.ProvideSnapshots = true;
                _videoDevice.SnapshotResolution = _snapshotCapabilities[snapshotResolutionsCombo.SelectedIndex];
                _videoDevice.SnapshotFrame += videoDevice_SnapshotFrame;

            }

           EnableConnectionControls(false);
           videoSourcePlayer.VideoSource = _videoDevice;              
           videoSourcePlayer.Start();

        }

}

Test using microscope

【问题讨论】:

  • 你确定显微镜不是背对前的吗?
  • 我不这么认为,因为我最初使用的是 DirectShowLib-2005 并且视频方向是正确的。但是,DirectShowLib 有点问题,有时视频源会锁定,需要重新启动我的应用程序。

标签: c# windows-7-x64 aforge


【解决方案1】:

很抱歉这么晚才发表此评论。 关于第一个不起作用的解决方案,您应该在 VideoCaptureDevice 对象而不是 VideoSource 上添加 NewFrame 事件。这样它应该可以工作

【讨论】:

    【解决方案2】:

    你可以使用代码:

     _videoDevice.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
     videoSourcePlayer.VideoSource = _videoDevice;
     videoSourcePlayer.Start();
    

    和:

    private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        eventArgs.Frame.RotateFlip(RotateFlipType.Rotate180FlipNone);
    }
    

    这对我有用。

    【讨论】:

      【解决方案3】:

      解决方案是使用来自 Aforge.Controls.videoSourcePlayer 事件的 NewFrame。

      在开始视频源之前订阅活动:

       videoSourcePlayer.VideoSource = _videoDevice;
       videoSourcePlayer.VideoSource.NewFrame += VideoSource_NewFrame; 
       videoSourcePlayer.Start();
      

      我试过这段代码:

      private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
      {
         eventArgs.Frame.RotateFlip(RotateFlipType.Rotate180FlipXY);
      }
      

      但这不起作用,我从文档中认为应该旋转新帧但没有在 videoSourcePlayer 中显示它。

      解决方法是将旋转后的位图显示到图片框中并隐藏视频播放器。

      private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
      {
            Mirror filter = new Mirror(true, true);
            filter.ApplyInPlace(img);
            pbxCamera.Image = img;
      }
      

      【讨论】:

      • 请原谅我这么快就发布了我对这个问题的答案。我只是想分享我学到的东西。我会接受其他人发布的最佳答案。
      猜你喜欢
      • 2021-01-01
      • 2012-08-23
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多