|
If i would say want to tint only one particular region of the texture obtained from VideoTexture.cs, how would I go about doing that?
|
|
|
|
|
Hi everyone,
When I run the code with this initialization (for the webcam):
this.webCam = new VideoComponent(this, 0);
I see only a black screen in the game window. But if look at the visual studio output text window, I see this error message, appearing continiously:
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll
¿Someone knows how to solve that problem? Thanks
|
|
|
|
|
Somebody fixed it below...
In this reply: Re: VS2008, XNA 3.0, DirectShow.NET 2.0 ... almost working MrDytmire 8:55 31 Jan '09
Again, the fix is:
-Inside of Videocomponent.cs
-Change:
public override void Draw(GameTime gameTime)
{
this.videoSprite.Begin();
...
}
-To this:
public override void Draw(GameTime gameTime)
{
this.videoSprite.Begin(SpriteBlendMode.None, SpriteSortMode.Deferred, SaveStateMode.SaveState);
...
}
|
|
|
|
|
Hey Stephen,
First, I'd like to thank you for sharing your code. It is very clear and helpful, and I've learnt a lot from it over the last week. I've used some of the code for an interactive art prototype based on webcam capture, and a colleague of mine is trying to use it overseas. He is running it on his new Macbook Pro (obviously running XP with reasonable resources). For some reason we're facing some framerate problems with our prototype.
We've decided to test with the original demo app that you've created, and we still experience very low framerate (always under 2fps). This is running with the motion detection mode set to none, and using is webcam. Using the webcam on other applications (such as Skype) works great (high framerates, reasonable resolution).
Do you have an idea what could be the cause for this problem??
Again, in any case, much gratitude for your effort.
Yossi
|
|
|
|
|
First, Sorry to my English.
But I was wondering about the this code for making texture.
yesterday I had try to this way
//
foreach (ModelMesh mesh in modeling.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.World = Matrix.CreateScale(scale) * Matrix.CreateTranslation(position);
effect.TextureEnabled = true;
effect.Texture = webCam.VideoTexture.VideoTexture2D; <<<<<<<<<<<<<<<<<<<<<<< write like this
effect.Projection = cameraProjectionMatrix;
effect.View = cameraViewMatrix;
}
mesh.Draw();
//
but that code just make a paused picture, that's not a movie;
please, Could Anyone help me? T_T
|
|
|
|
|
Hi Stephen,
First of all let me thank you for this nice article and source code.
I was playing around and tried to move towards 3D. Here is my draw method
public VertexPositionTexture[] quadVerts { get; set; }
public Vector3 quadPosition { get; set; }
public Matrix quadMatrix { get; set; }
public Texture2D quadTexture { get; set; }
public BasicEffect effect { get; set; }
public Transformation CameraTransformation { get; set; }
public override void Draw(GameTime gameTime)
{
quadTexture = VideoTexture.VideoTexture2D;
effect.Texture = quadTexture;
effect.World = CameraTransformation.Matrix;
effect.View = cameraManager.ActiveCamera.View;
effect.Projection = cameraManager.ActiveCamera.Projection;
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
GraphicsDevice.DrawUserPrimitives<vertexpositiontexture>(PrimitiveType.TriangleStrip,
quadVerts, 0, 2);
pass.End();
}
effect.End();
}
</vertexpositiontexture>
Where videoSprite methods draw the video just in front of the camera, hiding all models behind and GraphicsDevice.DrawUserPrimitives method draws the first Texture2D in a correct place in 3D world.
What do I need to do in order to play video, not the first picture from it?
Probably there are some other ways to move video into 3D space?
Thanks,
Alex.
|
|
|
|
|
I just downloaded it and really quickly made a vs2008 solution with the necessary changes (only two actually)
first when creating the 2d videotexture (some parameter that was absolete in 3.0) and
second changing the types for eventParam1, eventParam2 in the HandleGraphEvents method in VideoTexture.cs from int to IntPtr
I can only grab one frame then I'll get a bunch of exceptions for the rest of the frames for some reason.
You can get my version at http://ajden.towfeek.se/xnaVideoTexture.rar
Feel free to email me at ajden.towfeek [at sign] gmail.com if anybode solves the mistery, I'm not going to put too much effort into it.
Happy new year!
|
|
|
|
|
Hey I fixed it!
Here's the solution: Inside of Videocomponent.cs
Change:
public override void Draw(GameTime gameTime)
{
this.videoSprite.Begin();
this.videoSprite.Draw(this.videoTexture.VideoTexture2D, this.destinationRectangle, this.sourceRectangle, this.modulationColor, this.rotation, this.origin, this.spriteFlip, this.layerDepth);
this.videoSprite.End();
}
to this:
public override void Draw(GameTime gameTime)
{
this.videoSprite.Begin(SpriteBlendMode.None, SpriteSortMode.Deferred, SaveStateMode.SaveState);
this.videoSprite.Draw(this.videoTexture.VideoTexture2D, this.destinationRectangle, this.sourceRectangle, this.modulationColor, this.rotation, this.origin, this.spriteFlip, this.layerDepth);
this.videoSprite.End();
}
and it all works fine. Thanks for updating things to XNA 3.0!
|
|
|
|
|
hi, May I know how to get a frame or frames from the buffer of video stream captured from the camera using your component?
Thanks.
L
|
|
|
|
|
Hi
I cannot find the right Dshow dll anywhere.
Anyone got this file???
thanks
|
|
|
|
|
|
I tried none work, none extract to DirectShowLib-2005.dll
there are not that many versions which one is this 1.0 1.1 1.2...!!!!
thanks
|
|
|
|
|
Hi sashdude;
If you go to the following page:
http://sourceforge.net/project/showfiles.php?group_id=136334[^]
and scroll down to the section "File Releases" you will see a collapsable tree with an entry for "DirectShowNET". If you expand that tree (click the + sign) it will open up to show several versions, including V2.0, V1.5, V1.4. If you download either V2.0 (the file name is DirectShowLibV2-0.zip) or V1.5 (the file name is DirectShowLibV1-5.zip)and unzip them you will have several directories including a "lib" directory. If you look in that directory you will see the DirectShowLib-2005.dll file. Personally, I would use the V2.0 version today, although when I wrote the software I used the V1.5 version.
Steve.
|
|
|
|
|
hello,
I have a problem with the ToggleFullScreen function. if I use it then I lose connection with webcam.
please for any advice.
|
|
|
|
|
(XNA 2.0)
I am trying to capture a screen with a rectangle with video using your component and some other graphics.
In order to doing this I am doing:
if ( Game1.graphics.GraphicsDevice.Textures[0] != null )
Game1.graphics.GraphicsDevice.ResolveBackBuffer(screenshottexture);
But in your videotexture.class you do
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
...
this.graphics.Textures[0] = null;
this.videoTexture2D.SetData<Microsoft.Xna.Framework.Graphics.Color> (colorData);
}
And the "screenshottexture" obtained is a black screen. I guess this happens because when I resolve the backbuffer is null.
|
|
|
|
|
Great Article.
Constructor of the Texture2D has changed in the new version.
So if you want to use it with the new version, first
update the xna references so that you are referencing
to 2.0 and then change the lines where the texture is created
this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);
Cheers,
Mert
|
|
|
|
|
Thanks for noting this Mert.
There are a couple of other changes that are needed in the code to make it compile and run without error, and these can be found in the message "Changes Necessary for XNA 2.0" below.
I guess I really should upload the modified code so that people don't have this difficulty...
Cheers!
Steve.
|
|
|
|
|
I made a small test and works very well, but I have just a small question, where is the sound?
By the code it just read the frame and convert to a texture, now how can I play a video intro for example with sound support?
Thanks for the help and very nice component
|
|
|
|
|
Hello,
i have the same question. I have tryed to add a sound device to the graph, but ... i dont realy know what i have to do.
Have anybody some inpirations?
Best Regards,
Thorsten
|
|
|
|
|
I used your code successfully to play video from a tv card but I need to play from the composite video input of the tv card.
Can you give me some clues
|
|
|
|
|
XNA 2.0 made some "breaking changes" from XNA 1.0 that impact this code. Thanks to Odinlai for bringing this issue to my attention. To use this code with XNA Framework 2.0 change references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game from version 1.0 to 2.0 and make the following changes in the code files:
In VideoComponent.cs
FROM (248): private void LoadContent()
TO (248): protected override void LoadContent()
In VideoTexture.cs
FROM (155): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);
TO (155): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);
FROM (190): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);
TO (190): this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);
INSERT BETWEEN (618-619): this.graphics.Textures[0] = null; // Workaround suggested in https://connect.microsoft.com/feedback/Workaround.aspx?FeedbackID=318195&SiteID=226
In xnaVideoViewer.cs
INSERT BETWEEN (96-97): [Obsolete]
INSERT BETWEEN (115-116): [Obsolete]
The next update to this site will include these changes. In the meantime, please make the changes manually if you are affected by this issue.
Thanks.
Steve.
|
|
|
|
|
when i compile the VideoTexture.cs
an error occur:
Error 1 The name 'ResourceUsage' does not exist in the current context D:\fun project\webcam with xna\webcam with xna\VideoTexture.cs 155 92 webcam with xna
is my setting is wrong??
please help
|
|
|
|
|
Thanks for bringing this error to my attention.
Unfortunately, ResourceUsage has been removed from XNA Framework 2.0, creating a breaking change from XNA Framework 1.0. Methods that used to take ResourceUsage now take BufferUsage or TextureUsage. The Texture2D constructor in particular now requires a TextureUsage. This is also a breaking change from XNA Framework 1.0.
The easiest way to make the software work is to reference the Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game libraries for Version 1.0. I realize that this is unsatisfactory for anyone using the 2.0 frameworks (which I would prefer to use myself...)
I have made the changes necessary to compile the program under XNA 2.0. This required changing the following lines:
FROM:
this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, ResourceUsage.None, SurfaceFormat.Color, ResourceManagementMode.Automatic);//Version 1.0
TO:
this.videoTexture2D = new Texture2D(this.graphics, this.width, this.height, 1, TextureUsage.None, SurfaceFormat.Color);// Version 2.0
A few warnings are now generated about obsolete methods, and these should also be corrected.
Although this compiles without error, the following line now generates a runtime framework error:
this.videoTexture2D.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);
The error is:
"A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll"
This error can be thrown if the number of elements in the array colordata is not the same as the size of the Texture2D (it is), or if the Texture2D resource is currently set on the graphics device (maybe it is.) This looks like it is also an (undocumented) breaking change from XNA 1.0. I am afraid that more work will be needed to resolve this problem...
Steve.
|
|
|
|
|
I have been able to confirm this bug in the XNA 2.0 framework. Fortunately there is a workaround:
Change the VideoTexture.BufferCB() method to the following:
/// <summary>
/// Buffer Callback method from the DirectShow.NET ISampleGrabberCB interface. This method is called
/// when a new frame is grabbed by the SampleGrabber.
/// </summary>
/// <param name="SampleTime">The sample time.</param>
/// <param name="pBuffer">A pointer to the image buffer that contains the grabbed sample.</param>
/// <param name="BufferLen">The length of the image buffer containing the grabbed sample.</param>
/// <returns>0 = success.</returns>
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
byte[] bgrData = new byte[BufferLen];
Marshal.Copy(pBuffer, bgrData, 0, BufferLen);
Color[] colorData = new Color[BufferLen / 3];
for (int i = 0; i < colorData.Length; i++)
{
colorData[i] = new Microsoft.Xna.Framework.Graphics.Color(bgrData[3 * i + 2], bgrData[3 * i + 1], bgrData[3 * i]);
}
// The following line works in XNA 1.0 but generates an error in XNA 2.0
this.graphics.Textures[0] = null; // Workaround suggested in https://connect.microsoft.com/feedback/Workaround.aspx?FeedbackID=318195&SiteID=226
this.videoTexture2D.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);
RaiseNewVideoTextureEvent(); // notify subscribers, if any.
return 0;
}
This should allow the code to operate correctly under XNA 2.0.
Steve.
|
|
|
|
|
I can't create two video components to play two different videos simultaneously.
|
|
|
|
|