Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# OpenGL graphics , +
Hi!!
First of all, sorry if my english is bad, I am not a native .
I've been working with emgu cv(opencv wrapper to capture images from a webcam and using its functions to proccess this images.
I also detect the hand and track the hand movement...
 
Now, I need to draw a kind of earth or just an object according to the hand position, for which sharpGL is perfect for perspective transformation and so on. My problem is that I can't achieve that.
 

 
I don't know how to say to sharpGL "you guy, draw that object within this hand tracking window"
Is it impossible what I want to do? I am desperate... any help would be great. Thanks in advance
 
see this video if you're still confused about what I meant (http://www.youtube.com/watch?v=ccL4t36sVvg)
 
so far, I've just translated this code http://blog.damiles.com/2008/10/opencv-opengl/ into C#
 
and here's code snippet
 
private void openGLControl_OpenGLInitialized(object sender, EventArgs e)
        {
            //  TODO: Initialise OpenGL here.

            //  The texture identifier.
            uint[] textures = new uint[1];
 
            //  Get the OpenGL object.
            OpenGL gl = openGLControl1.OpenGL;
 
            //texture.Create(gl);

            //  Get one texture id, and stick it into the textures array.
            gl.GenTextures(1, textures);
 
            //  Bind the texture.
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
 
            //  A bit of extra initialisation here, we have to enable textures.
            gl.Enable(OpenGL.GL_TEXTURE_2D);
 
            //  Specify linear filtering.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST);
 
            gl.PixelStore(OpenGL.GL_UNPACK_ALIGNMENT, 1);
 
            //  Set the clear color.
            gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
        }
 

private void openGLControl_Resized(object sender, EventArgs e)
        {
            //  TODO: Set the projection matrix here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl1.OpenGL;
            //  Set the projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
 
            //  Load the identity.
            gl.LoadIdentity();
 
            //  Create a perspective transformation.
            gl.Perspective(60.0f, (double)Width / (double)Height, 0.01, 100.0);
 
            //  Use the 'look at' helper function to position and aim the camera.
            gl.LookAt(-5, 5, -5, 0, 0, 0, 0, 1, 0);
 
            //  Set the modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
 
and finally draw an object
 
private void openGLControl_OpenGLDraw(object sender, PaintEventArgs e)
        {
            //  Get the OpenGL object.
            OpenGL gl = openGLControl1.OpenGL;
            
            if (capture == null)
            {
                this.start_capture();
            }
            
            if (capture != null)
            {
                Image<Bgr, Byte> ImageFrame = capture.QueryFrame();
 
                //I'm trying to use some algorithm using the code from sample (sharpGLTextureExample)
                //first, I make an Bitmap object that I take from queryframe(convert it to bitmap first)
                Bitmap image = new Bitmap(ImageFrame.ToBitmap());
 

                //  Clear the color and depth buffer.
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                //ImageFrame.Draw(new Rectangle(2, 2, 2, 2), new Bgr(Color.Aqua), 2);
                
                
                //  Load the identity matrix.
                gl.LoadIdentity();
 
                //then, Lock the image bits (so that we can pass them to OGL).
                BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
 
                gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
                //gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, ImageFrame.Width, ImageFrame.Height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, ImageFrame);
                gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA, ImageFrame.Width, ImageFrame.Height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
 
                
                //gl.Begin(OpenGL.GL_QUADS);
                
                //gl.TexCoord(0, 0); gl.Vertex(-1, -1, 0);
                //gl.TexCoord(1, 0); gl.Vertex(1, -1, 0);
                //gl.TexCoord(1, 5); gl.Vertex(1, 1, 0);
                //gl.TexCoord(0, 1); gl.Vertex(-1, 1, 0);
                //gl.End();
                
                //gl.Flush();
                
                //texture.Bind(gl);
                //
                //CamImageBox.Image = ImageFrame;
            }
            
        }
 
but the output always return an white, no texture on it...
 

 

I've also consindering to use Texture class, but it's no use..because there's no method which the input parameter is the frame...
 

I appreciate your answer...
 

regards.
Posted 1-May-12 9:10am
Comments
sara magdi at 3-May-12 11:37am
   
Reason for my vote of 5
i want to do the same thing and have the same error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 1 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100