来自Windows USB设备的视频流使用AForge颠倒了

时间:2015-09-07 12:50:16

标签: c# windows-7-x64 aforge

我正在使用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();

        }

}

Celestron 44302-B

Test using microscope Video feed using Aforge.net

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

解决方案是使用来自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;
}

Rotated image

答案 2 :(得分:0)

您可以使用代码:

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

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

这适合我。

相关问题