hi
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
hi
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
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%5FDetection.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.
- Copy the VideoTexture.cs file into your own project.
- Change the namespace in the VideoTexture.cs file to the name of your project namespace.
- Add a reference to DirectShowLib-2005.dll from the DirectShow.NET library.
- 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.
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!