How to set background in OpenGL captured image from OpenCV

Posted by user325487 on Stack Overflow See other posts from Stack Overflow or by user325487
Published on 2010-04-25T17:45:53Z Indexed on 2010/04/25 17:53 UTC
Read the original article Hit count: 223

Filed under:
|
|
|

Hey All,

i'm relatively new to Artoolkitplus and openGL

i'm having a tough time getting the image i capture through openCV to be set as the background image in OpenGL ...

I also cannot convert the image i take through the camera using opencv to be scaled to 320x280 from 640x480 .. i also have to save my image and load if for things to work...

here's my code

////////////

int findMarker() { IplImage* image = cvQueryFrame( capture );

if( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); return -1; } if( !image ) { fprintf( stderr, "ERROR: frame is null...\n" ); getchar(); }

//cvShowImage( "Capture", frame ); //image = cvCloneImage( frame );

try{ if(!cvSaveImage("immagineTmp.jpg",image)) printf("Could not save\n"); } catch(void*) {}

image = cvLoadImage("immagineTmp.jpg", 1);

cvShowImage( "Image", image ); glLoadIdentity();

////////////// glDisable(GL_DEPTH_TEST); glOrtho(0,640,0,480,-1,1);

glGenTextures(1, &bgid); glBindTexture(GL_TEXTURE_2D, bgid);

// Create Linear Filtered Texture glBindTexture(GL_TEXTURE_2D, bgid); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, image->width, image->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->imageData);

glBindTexture(GL_TEXTURE_2D, bgid);

glBegin(GL_QUADS);

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2f, -1.0f, -2.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.2f, -1.0f, -2.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.2f, 1.0f, -2.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.2f, 1.0f, -2.0f);

glEnd(); glEnable(GL_DEPTH_TEST); glLoadIdentity();

////////////

// do the OpenGL camera setup glMatrixMode(GL_PROJECTION); glLoadMatrixf(tracker->getProjectionMatrix());

int markerId = tracker->calc((unsigned char *)(image->imageData)); float conf = tracker->getConfidence();

// use the result of calc() to setup the OpenGL transformation glMatrixMode(GL_MODELVIEW); glLoadMatrixf(tracker->getModelViewMatrix());

if(markerId!=-1) { printf("\n\nFound marker %d (confidence %d%%)\n\nPose-Matrix:\n ", markerId, (int(conf*100.0f))); for(int i=0; i<16; i++) printf("%.2f %s", tracker->getModelViewMatrix()[i], (i%4==3)?"\n " : ""); }

cvReleaseImage(&image); return 0; }

© Stack Overflow or respective owner

Related posts about opengl

Related posts about opencv