English 中文(简体)
webcam calling in xna
原标题:
  • 时间:2009-11-24 12:12:36
  •  标签:
  • xna
  • webcam

i am new in xna

i want to use my webcam and make webcam image as a background texture for 3D models

is there a function that calls webcam

thanks for suggestions

问题回答

If you check out the AForge framework you ll find a sample program that does motion detection on webcam feeds.

http://code.google.com/p/aforge/

This framework has a very easy to get webcam feeds.

Basically ends up

VideoCaptureDevice device = new VideoCaptureDevice(monikor);
device.NewFrame += new AForge.Video.NewFrameEventHandler(webcam_NewFrame);
webcam.Start();

where you can get the webcam s monikor by calling code similar to...

FilterInfoCollection webcamList = new FilterInfoCollection(FilterCategory.VideoInputDevice);

foreach(FilterInfo info in webcamList)
{
    string monikor = info.MonikorString;
    string deviceName = info.Name;
}

This is the best/easiest way i ve come across to get webcam feeds.

Then you can convert the Bitmap into a Texture2D and display as you wish!

I ran into this problem myself a while ago, it s quite a messy solution that I came up with.

First, you need to use the motion_src library, you can find that here:

http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx

That tutorial is all about motion detection, but if you download the demo code you can take the bit where it captures the input from the camera.

Now, add that as a reference to your xna project.

Once you have the system set up capturing a feed from the camera (all the details are in that tutorial, I won t repeat them here) you ll need to copy the feed (which is captured into a System.Drawing.Bitmap into an xna texture.

Texture2D image;

b = (System.Drawing.Bitmap)camera.LastFrame.Clone();
for (int j = 0; j < image.Height; j++)
{
    for (int i = 0; i < image.Width; i++)
    {
        c = b.GetPixel(i, j);
        colours[i + j * image.Width] = new Color(c.R, c.G, c.B, byte.MaxValue);
    }
}
image.SetData<Color>(colours);

You can then display the image texture using a normal call to spritebatch :)

You could use the third party VideoTexture class. It can use a webcam or an AVI, MPEG, or WMV and gives you access to a Texture2D object with the current frame as the image that can be used with spritebatch or applied to 3D objects.

  1. Copy the VideoTexture.cs file into your own project.
  2. Change the namespace in the VideoTexture.cs file to the name of your project namespace.
  3. Add a reference to DirectShowLib-2005.dll from the DirectShow.NET library.
  4. Compile it. The VideoTexture class should now be available in your project.

I ve never used it, but if you download the documentation it should help. It should just be a matter of creating a VideoTexture, and using its VideoTexture2D property to retrieve the Texture2D. Then you could set that as the texture for each effect for some 3D object.





相关问题
copying a texture in xna into another texture

I am loading a Texture2D that contains multiple sprite textures. I would like to pull the individual textures out when I load the initial Texture to store into separate Texture2D objects, but can t ...

XNA Antialias question!

I ve got problems with XNA and antialiasing. I can activate it using graphics.PreferMultiSampling = true; graphics.ApplyChanges(); however - it s only 2x antialiasing. Even if I set ...

Take screen shot in XNA

How can I take a screen shot of the screen in XNA? Is it possible without System.Drawing.Graphics.CopyFromScreen or Win32API? If it s not possible, Is there any way to draw a System.Drawing.Bitmap to ...

XNA .Fbx textures

I m using the standard .fbx importer with custom shaders in XNA. The .fbx model is UV wrapped properly and is textured appropriately when I use BasicEffect. However when I use my custom effect I have ...

Can t install XNA

I m trying to install XNA. When the installation starts I got an error that says "XNA GSE 1.0 refresh requires Visual C# 2005 express edition sp1..." I use Windows 7 and I have Visual Studio 2008 &...

Is there a 3D equivalant to clamp in XNA?

I m building a 3D game but i only plan on using a 2D perspective thus not taking the z axis into the equasion, i want to be able to limit the movement of one of my models so it doesn t move out of the ...

Fetching the vertices from the backbuffer (HLSL) on XNA

Hello and sorry for the obscure title :} I`ll try to explain the best i can. First of all, i am new to HLSL but i understand about the pipeline and stuff that are from the fairy world. What i`m ...

Simple XNA 2d physics library

Working on a 2D project and wanted some recommendations on a simple 2d physics library for use in C# with the XNA framework. I was looking at Farseer or physics2d. Anyone have any other suggestions? ...

热门标签