来自 Windows USB 设备的视频流使用 AForge 颠倒
Video stream from Windows USB device is upside down using AForge
我正在使用 AForge.net version 2.25 to display video feed from a USB digital microscope, Celestron 44302-B。使用显微镜软件,视频可以在 Windows 7 x64 工作站上正确显示。
代码基于 Aforge 的示例应用程序。结果如下所示,其中 AForge.Controls.videoSourcePlayer 中的视频源是颠倒的。
我可以轻松翻转单个位图(从视频流中截取的快照),但我希望允许用户在连接视频源和 运行.[=16= 时调整显微镜的方向和聚焦]
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
解决方案是使用来自 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;
}
抱歉这么晚才发表这条评论。
关于您的第一个不起作用的解决方案,您应该在 VideoCaptureDevice 对象而不是 VideoSource 上添加 NewFrame 事件。这样应该可以工作
您可以使用代码:
_videoDevice.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
videoSourcePlayer.VideoSource = _videoDevice;
videoSourcePlayer.Start();
和:
private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
eventArgs.Frame.RotateFlip(RotateFlipType.Rotate180FlipNone);
}
这对我有用。
我正在使用 AForge.net version 2.25 to display video feed from a USB digital microscope, Celestron 44302-B。使用显微镜软件,视频可以在 Windows 7 x64 工作站上正确显示。
代码基于 Aforge 的示例应用程序。结果如下所示,其中 AForge.Controls.videoSourcePlayer 中的视频源是颠倒的。
我可以轻松翻转单个位图(从视频流中截取的快照),但我希望允许用户在连接视频源和 运行.[=16= 时调整显微镜的方向和聚焦]
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
解决方案是使用来自 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;
}
抱歉这么晚才发表这条评论。 关于您的第一个不起作用的解决方案,您应该在 VideoCaptureDevice 对象而不是 VideoSource 上添加 NewFrame 事件。这样应该可以工作
您可以使用代码:
_videoDevice.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
videoSourcePlayer.VideoSource = _videoDevice;
videoSourcePlayer.Start();
和:
private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
eventArgs.Frame.RotateFlip(RotateFlipType.Rotate180FlipNone);
}
这对我有用。