XNA的VideoTexture类和网络摄像头应用程序(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/videotexture-class-and-webcam-application-for-xna-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2205 个词 阅读量 0XNA的VideoTexture类和网络摄像头应用程序(译文)
原文地址:https://www.codeproject.com/Articles/19707/VideoTexture-Class-and-Webcam-Application-for-XNA
原文作者:Stephen Bogner
译文由本站 robot-v1.0 翻译
前言
A managed C# video texture class, demonstrated in an XNA WebCamComponent and used in a webcam application
在XNA WebCamComponent中演示并在网络摄像头应用程序中使用的托管C#视频纹理类
- 下载XnaVideo可执行文件-100.6 Kb(Download XnaVideo executables - 100.6 Kb)
- 下载XnaVideo源-25.2 Kb(Download XnaVideo source - 25.2 Kb)
- 下载MSDN风格的XnaVideo文档-65.8 Kb(Download MSDN-style XnaVideo documentation - 65.8 Kb)
图1.运行中的xnaVideoViewer应用程序的屏幕截图(Figure 1. Screenshot of the xnaVideoViewer application in action)
介绍(Introduction)
“视频纹理"是一类重要的多媒体对象,在视频会议,可视化,游戏,机器人技术和图像分析中具有有趣的用途.最明显的用途(也是我在本项目中关注的用途)是将流视频从网络摄像头映射到(“Video textures” are an important class of multimedia objects with interesting uses in video conferencing, visualization, gaming, robotics and image analysis. The most obvious use – and therefore the usage that I have focused on in this project – is to map streaming video from a webcam onto a) Texture2D
目的.然后将其应用于Sprite,并在XNA应用程序中显示为实时视频窗口.除了通过任何DirectX视频设备播放实时视频之外,(object. This is then applied to a sprite and presented as a live video window within an XNA application. In addition to consuming live video from any of your DirectX video devices, the) VideoTexture
该类还能够使用AVI,MPEG和WMV格式的视频剪辑.(class is also able to consume AVI, MPEG and WMV format video clips.)
的(The) VideoTexture
类公开了一个名为(class exposes a property called) VideoTexture2D
,旨在在任何正常情况下都可以使用(, which is intended to be usable wherever a normal) Texture2D
对象可能在XNA中使用.这意味着它可以用于将动态视频纹理应用于子图形和几何网格/模型.就像任何其他纹理一样,也可以通过像素,顶点和几何着色器对其进行操作.(object might be used within XNA. This means that it can be used to apply a dynamic video texture onto both sprites and geometric meshes/models. It can also be manipulated by pixel, vertex and geometry shaders, just like any other texture.)
使用代码(Using the code)
要使用(To use the) VideoTexture
上课时,您应该:(class, you should:)
- 复制(Copy the)**VideoTexture.cs(VideoTexture.cs)**归档到您自己的项目中.(file into your own project.)
- 更改名称空间(Change the namespace in the)**VideoTexture.cs(VideoTexture.cs)**文件命名为项目名称空间的名称.(file to the name of your project namespace.)
- 添加参考(Add a reference to)**DirectShowLib-2005.dll(DirectShowLib-2005.dll)**来自(from the) DirectShow.NET(DirectShow.NET) 图书馆.(library.)
- 编译它.的(Compile it. The)
VideoTexture
类现在应该在您的项目中可用.(class should now be available in your project.) 的(The)XnaVideoViewer
该应用程序演示了(application demonstrates the usage of)VideoComponent
,这反过来说明了(, which in turn demonstrates the usage of the)VideoTexture
类.(class.)
兴趣点(Points of interest)
- 的(The)
VideoTexture
班级取决于托管(class depends upon the managed) DirectShow.NET(DirectShow.NET) 图书馆.(library.) - 的(The)
VideoTexture.VideoTexture2D
可以由其他类轮询属性以获取最新的视频帧.这就是发生的情况,例如(property can be polled by other classes to get the most current frame of video. This is what happens, for example, in the)VideoComponent.Draw()
方法.或者,要使用的类(method. Alternatively, classes that want to use)VideoTexture
可以订阅(can subscribe to)VideoTexture.NewVideoTextureEvent
并将当前视频帧推送到他们(and have the current frame of video pushed to them in)NewVideoTextureEventArgs
每次从视频流中获取新帧时.(each time a new frame is grabbed from the video stream.) VideoComponent
自动将自身注册为使用该服务的游戏应用程序中的服务.可以通过服务集合通过应用程序使用的任何其他组件来引用它.(automatically registers itself as a service within the game application that uses it. It can be referenced through the Services collection via any other components used by the application.)- 由于XNA的框架局限性-特别是缺少(Due to framework limitations within XNA – specifically, the absence of the)
System.Windows
名称空间-所需的视频输入源(即摄像机或文件)需要在(namespace – the desired source of video input (i.e. cameras or files) needs to be coded manually in the)xnaVideoViewer
应用.这是在(application. This is done in the)LoadComponents()
方法.(method.) - 的(The)
xnaVideoViewer
应用程序将以下命令映射到XBox 360控制器:Run =A(绿色);暂停=Y(黄色);停止=B(红色);退出=返回.(application maps the following commands to the XBox 360 controller: Run = A (Green); Pause = Y (Yellow); Stop = B (Red); Exit = Back.) - 的(The)
VideoTexture
类已用于为实验性HUD应用程序提供视频流.最近,它已用于通过顶点着色器流式传输视频纹理,以实时校正镜头失真,以此作为将流缝合到视频马赛克中的前奏.(class has been used to provide the video stream for an experimental HUD application. It has recently been used to stream video textures through vertex shaders to correct lens distortions in real-time as a prelude to stitching the streams into a video mosaic.)
历史(History)
- 2007年7月30日-版本1.1.0.0已上传到CodeProject.更改包括重命名和重大重构(30 July 2007 - Version 1.1.0.0 uploaded to CodeProject. Changes include renaming and significant refactoring of the)
xnaVideoViewer
,(,)VideoComponent
和(and)VideoTexture
类.增加了对AVI,MPEG和WMV视频文件的支持.添加了对运行,暂停和停止的支持.对循环视频剪辑的支持已添加.添加了两个单独的方法来捕获和处理DirectShow筛选器图事件.添加了其他错误处理代码.(classes. Support for AVI, MPEG and WMV video files was added. Support for Run, Pause and Stop was added. Support for Looping video clips was added. Two separate methods for capturing and handling DirectShow Filter Graph events were added. Additional error handling code was added.) - 2007年7月21日-1.0.0.0版已上传到CodeProject.(21 July 2007 - Version 1.0.0.0 uploaded to CodeProject.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET Windows Visual-Studio Dev 新闻 翻译