2015-09-07 52 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); 
} 

這對我的作品。