Page 1 of 2

2d texture visualization problem

PostPosted: Tue Jan 24, 2012 9:41 pm
by mitko29
Hi,andrew I started making the 3D augmented reality but when I pass the camera bitmap to the method BitmapToXnaTexture I dont know how to load it inside xna content pipeline.
When you have time please tell me how to add it in LoadContent().

Re: 2d texture visualization problem

PostPosted: Tue Jan 24, 2012 9:48 pm
by andrew.kirillov
Hello,

Don't know either. As I wrote in my article (and I do the same in Glyph Recognition Studio), I simply convert System.Graphics.Bitmap into XNA Texture2D. Then I render it using SpriteBatch. See XNATextureFromBitmap() in the article or source code.

Re: 2d texture visualization problem

PostPosted: Tue Jan 24, 2012 10:02 pm
by mitko29
andrew.kirillov wrote:Hello,

Don't know either. As I wrote in my article (and I do the same in Glyph Recognition Studio), I simply convert System.Graphics.Bitmap into XNA Texture2D. Then I render it using SpriteBatch. See XNATextureFromBitmap() in the article or source code.

Well I already saw the method Xnatexturefrombitmap() and I have the source code , but the main problem is that when I convert it to texture 2d and try to draw it from spriteBatch I don't have anything in xna game windows I mean I dont see the camera video inside the game windows.

Thanks in advance for you answer

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 10:50 am
by mitko29
Ok andrew I was able to draw my video in the xna windows , but when I open task manager and see memory I just can believe how much its need for 20 second :D .
Is there a way to dispose or set free the images I don't need ?

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 11:23 am
by andrew.kirillov
Images tend to have Dispose() method. If you don't call it, then ... memory usage will grow.

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 12:02 pm
by mitko29
Ok , and how to call EstimateGlyphPose from GlyphTracker ?
When I do this:
GlyphTracker tracker = new GlyphTracker();
tracker.EstimateGlyphPose - I don't see it but in your project source code inside glyphtracker.cs i can clearly see it :)

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 12:16 pm
by andrew.kirillov
Hmmm ... Not sure what you really do.

GlyphTracker() is a private method - maybe this is a reason why you "don't see it"? As for me, I call GlyphTracker.TrackGlyphs(), which does all the job.

P.S. Take some time and have a look at sample application. Same actually is shown here. If you ignore samples, then there is not much I can help with.

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 4:19 pm
by mitko29
I am not ignoring the source code but there is no use of it .............

The only think I can't understand is how the glyphtracker is suppose to give me the posit algorithm - in your source you only use the glyphtracker to count the markers and then you put all that info inside GlyphTitle.

Re: 2d texture visualization problem

PostPosted: Fri Jan 27, 2012 4:32 pm
by andrew.kirillov
mitko29 wrote:but there is no use of it .............

Don't use it then. Just delete it and write yours from scratch.

mitko29 wrote:how the glyphtracker is suppose to give me the posit algorithm

GlyphTracker calls EstimatePose() method of posit algorithm and then provides estimated pose as ExtractedGlyphData.TransformationMatrix. If go through the code, you should see that.

Re: 2d texture visualization problem

PostPosted: Sat Jan 28, 2012 4:02 pm
by mitko29
andrew.kirillov wrote:
mitko29 wrote:but there is no use of it .............

Don't use it then. Just delete it and write yours from scratch.

mitko29 wrote:how the glyphtracker is suppose to give me the posit algorithm

GlyphTracker calls EstimatePose() method of posit algorithm and then provides estimated pose as ExtractedGlyphData.TransformationMatrix. If go through the code, you should see that.


Sorry I didn't want to be rude just wasn't my day.
What I wanted to say is that on the project I am working the source code is not helping me :)
And I don't wan't to think that I don't appreciate the work your are doing , or the one you already have done , sometimes I just need more time to get into the things .

If you don't mind I have one last question : :D
I am trying to draw the matrix but I always get this error : Object reference not set to an instance of an object.
Here's my code for void Draw and void Update:
Void UPDATE:
Code: Select all
if (array != null)
            {               
                //for (int i = 0; i < array.Length; i++)
               // {
                    pointx = array[0].X;
                    pointy = array[1].Y;                   
                //}
                mm = new Microsoft.Xna.Framework.Vector3(pointx, pointy, 10.0f); 
            }

Void Draw:
Code: Select all
if (array != null)
                {
                    if ((myModel != null) && (myModel.Meshes.Count > 0))
                    {
                        float modelSize = 113;
                        ModelMesh mesh = myModel.Meshes[0];                                                                             
                        Matrix rotation = Matrix.CreateFromYawPitchRoll(
                        -yaw , -pitch, roll);
                        Matrix translation = Matrix.CreateTranslation(mm.X, mm.Y, mm.Z);
                        Matrix scaling = Matrix.CreateScale(modelSize);
//error
                        Matrix viewMatrix = Matrix.CreateLookAt(
                        new Vector3(0, 0, 3), Vector3.Zero,Vector3.Up);
                        Matrix projectionMatrix = Matrix.CreatePerspective(
                            1, 1 / GraphicsDevice.Viewport.AspectRatio, 1f, 10000);
                        Matrix world = Matrix.CreateScale(1 / mesh.BoundingSphere.Radius) *
                        scaling * rotation * translation;
                        foreach (Effect effect in mesh.Effects)
                        {
                            if (effect is BasicEffect)
                            {
                                ((BasicEffect)effect).EnableDefaultLighting();
                            }
                            effect.Parameters["World"].SetValue(world);
//error
                            effect.Parameters["View"].SetValue(viewMatrix);
                            effect.Parameters["Projection"].SetValue(projectionMatrix);
                        }
                        mesh.Draw();
                    }
                }


P.P: I forgot to set the Matrix4x4 :D