I have build successfull http://sourceforge.net/projects/opencvlibrary/ to grab image from my notebook webcam ....

i hack this lib code to is possibel to run on window MINGW compiler ...
i not tested on linux but i am sure is run on /dev/videoxx

subversion ....
https://qt-webdav.svn.sourceforge.ne...t4_demo_mingw/

the qt4 demo is running .... and display a live image motion ...

Now my question, how i can grab more image to compose a avi/mpg4 film? with or withtout audio?


Qt Code:
  1. QtGLContext::QtGLContext(QWidget* parent /*= 0*/,
  2. const QGLWidget* sharedWidget /*= 0*/, Qt::WFlags f /*= 0*/) : QGLWidget(parent, sharedWidget, f), m_imgP(0), m_mousePressed(false)
  3. {
  4.  
  5. //////qDebug() << "### total cams = " << ncams;
  6.  
  7.  
  8. capture = cvCaptureFromCAM( CV_CAP_ANY );
  9.  
  10. if (capture) {
  11. SelfUpdate();
  12. }
  13. }
  14.  
  15. void QtGLContext::SelfUpdate()
  16. {
  17.  
  18. IplImage* imgPtr = cvQueryFrame( capture );
  19. setImage((unsigned char*)imgPtr->imageData, imgPtr->width, imgPtr->height, imgPtr->nChannels * imgPtr->depth , true);
  20. QTimer::singleShot(80, this, SLOT(SelfUpdate()));
  21. }
  22.  
  23.  
  24.  
  25. bool QtGLContext::setImage(
  26. unsigned char* imgP,
  27. const int width,
  28. const int height,
  29. const int pixeldepth,
  30. const bool flipped /*=false*/)
  31. {
  32. m_imgP = imgP; m_width = width; m_height = height; m_pixeldepth = pixeldepth;
  33. m_flipped = flipped;
  34. this->updateGL();
  35.  
  36. // only 8, 24 and 32 bit images are supported
  37. if (!imgP || (pixeldepth!=8 && pixeldepth!=24 && pixeldepth!=32))
  38. return false;
  39. glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
  40. // calculate texture size
  41. m_texWidth = NextLargerPowerOfTwo(m_width);
  42. m_texHeight = NextLargerPowerOfTwo(m_height);
  43. // create texture memory
  44. unsigned char* textureGL = new GLubyte[m_texHeight*m_texWidth* (pixeldepth>>3)];
  45. // calculate texture coordinates for image
  46. m_texUpperLeftX = float (m_texWidth-m_width) / (float) (m_texWidth);
  47. m_texUpperLeftY = float (m_texHeight-m_height) / (float) (m_texHeight);
  48. m_texLowerRightX = 1.0; // (float) (_texWidth) / (float) _height;
  49. m_texLowerRightY = 1.0; // (float) (_texHeight) / (float) _width;
  50.  
  51. // tell OpenGL which texture "id" we will be working with.:
  52. glBindTexture(GL_TEXTURE_2D, m_texNameGL);
  53. // tell OpenGL that the pixel data which is going to be passed to it is aligned in byte order:
  54. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  55.  
  56. // set the various parameters for the current OpenGL texture:
  57. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  58. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  59. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  60. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  61.  
  62. // tell OpenGL how the texture will act when it is rendered into a scene:
  63. // The GL_MODULATE attribute allows you to apply effects such as lighting
  64. // and coloring to your texture. If you do not want lighting and coloring to effect
  65. // your texture and you would like to display the texture unchanged when coloring
  66. // is applied replace GL_MODULATE with GL_DECAL
  67. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  68.  
  69. //glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, _texWidth, _texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, img->data());
  70. switch(m_pixeldepth) {
  71. case 8:
  72. glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_texWidth, m_texHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,textureGL);
  73. break;
  74. case 24:
  75. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_texWidth,m_texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, textureGL);
  76. break;
  77. case 32:
  78. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_texWidth,m_texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureGL);
  79. break;
  80. default:
  81. glDisable(GL_TEXTURE_2D);
  82. delete[] textureGL;
  83. return false;
  84. }
  85.  
  86.  
  87.  
  88. glDisable(GL_TEXTURE_2D);
  89. //glFlush();
  90. delete[] textureGL;
  91. resetBox();
  92. return true;
  93. }
To copy to clipboard, switch view to plain text mode