2015-09-07 53 views
0

来自Windows USB设备的视频流是颠倒的我正在使用AForge.net version 2.25来显示USB数字显微镜的视频输入,Celestron 44302-B。使用显微镜软件,可以在Windows 7 x64工作站上正确显示视频。使用AForge

代码基于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

+0

你确定显微镜不是回到前面吗? –

+0

我不这么认为,因为我最初使用了DirectShowLib-2005,视频方向正确。但是,DirectShowLib有点bug,偶尔视频源会锁定,需要我的应用程序重新启动。 –

回答

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中。

解决方案是将旋转后的位图显示到一个picturebox并隐藏该videoplayer。

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

Rotated image

+0

请原谅我这么快就发布自己的答案。我只是想分享我学到的东西。我会接受别人发布的最佳答案。 –

2

对不起,这么晚发布此评论。 关于您的第一个解决方案无效,您应该在VideoCaptureDevice对象而不是VideoSource上添加NewFrame事件。这样,它应该工作

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); 
} 

这对我的作品。