View unanswered posts | View active topics It is currently Sat Dec 07, 2019 12:17 am



Reply to topic  [ 4 posts ] 
 Using OpenCV webcam video capture movie 
Author Message
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Using OpenCV webcam video capture movie
Hi,
With GLC_lib and OpenCV, it' easy to capture webcam movie and to view it as a texture.
Attachment:
opencv.jpg
opencv.jpg [ 158.71 KiB | Viewed 8552 times ]


If you want more informations, reply to this topic.

@+

Laurent Ribon.


Fri Mar 04, 2011 11:37 pm
Profile

Joined: Thu Oct 28, 2010 10:55 pm
Posts: 17
Post Re: Using OpenCV webcam video capture movie
This looks interesting, more detailed information please. Thanks!


Mon Mar 07, 2011 5:52 pm
Profile
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Re: Using OpenCV webcam video capture movie
jeffer wrote:
This looks interesting, more detailed information please. Thanks!


I used opencv 2.2.0 for Mac OS X and of course GLC_lib.
I start this test from the exemple07 of GLC_lib
After a few Google search, I have found a way to convert opencv Image into QImage :
Code:
QImage GLWidget::IplImage2QImage(IplImage *iplImg)
{
   int h = iplImg->height;
   int w = iplImg->width;
   int channels = iplImg->nChannels;
   QImage qimg(w, h, QImage::Format_ARGB32);
   char *data = iplImg->imageData;

   for (int y = 0; y < h; y++, data += iplImg->widthStep)
   {
      for (int x = 0; x < w; x++)
      {
         char r, g, b, a = 0;
         if (channels == 1)
         {
            r = data[x * channels];
            g = data[x * channels];
            b = data[x * channels];
         }
         else if (channels == 3 || channels == 4)
         {
            r = data[x * channels + 2];
            g = data[x * channels + 1];
            b = data[x * channels];
         }

         if (channels == 4)
         {
            a = data[x * channels + 3];
            qimg.setPixel(x, y, qRgba(r, g, b, a));
         }
         else
         {
            qimg.setPixel(x, y, qRgb(r, g, b));
         }
      }
   }
   return qimg;
}


Constructor of my GLWidget :
Code:
GLWidget::GLWidget(QWidget *p_parent)
: QGLWidget(p_parent)
, m_Light()
, m_World()
, m_GlView(this)
, m_MoverController()
, m_MotionTimer()
, m_pCapture(NULL)
, m_pTexturedMaterial(NULL)
{
   m_Light.setPosition(1.0, 1.0, 1.0);

   QColor repColor;
   repColor.setRgbF(1.0, 0.11372, 0.11372, 1.0);
   m_MoverController= GLC_Factory::instance()->createDefaultMoverController(repColor, &m_GlView);

   m_GlView.cameraHandle()->setDefaultUpVector(glc::Z_AXIS);
   m_GlView.cameraHandle()->setIsoView();

   // Create objects to display
   CreateScene();
   connect(&m_MotionTimer, SIGNAL(timeout()), this, SLOT(updateTexture()));

   setAttribute(Qt::WA_AcceptTouchEvents, true);
}

The create scene method :
Code:
void GLWidget::CreateScene()
{
   // Load Backfround image.
   m_GlView.loadBackGroundImage(":fond_exemple07.png");

   // create a material with the specified texture
   // test OpenCV
   m_pCapture = cvCreateCameraCapture( -1 );

   IplImage *iplImage;
   cvGrabFrame(m_pCapture);
   iplImage = cvRetrieveFrame(m_pCapture);

   const double h = static_cast<double>(iplImage->height);
   const double w = static_cast<double>(iplImage->width);

   QImage textureImage= IplImage2QImage(iplImage);
   GLC_Texture* pTexture= GLC_Factory::instance()->createTexture(textureImage);
   m_pTexturedMaterial= new GLC_Material(pTexture, "");

   GLC_3DRep rep= GLC_Factory::instance()->createRectangle(w, h);
   rep.geomAt(0)->addMaterial(m_pTexturedMaterial);
   GLC_StructReference* pRef= new GLC_StructReference();
   pRef->setRepresentation(rep);
   const int size= 8;
   for (int i= 0; i < size; ++i)
   {
      const double deltaX= static_cast<double>(i) * w + (w / 10.0);
      GLC_Matrix4x4 matrix1(deltaX, 0.0, 0.0);

      for (int j= 0; j < size; ++j)
      {
         const double deltaY= static_cast<double>(j) * h + (h / 10.0);
         GLC_Matrix4x4 matrix(GLC_Matrix4x4(0.0, deltaY, 0.0) * matrix1);

         GLC_StructInstance* pInstance= new GLC_StructInstance(pRef);
         pInstance->move(matrix);
         m_World.rootOccurence()->addChild(pInstance);
      }

   }

   m_MotionTimer.start(60);

}

And finally the update texture method :
Code:
void GLWidget::updateTexture()
{
   if ( NULL != m_pTexturedMaterial)
   {
      IplImage *iplImage;
      cvGrabFrame(m_pCapture);
      iplImage = cvRetrieveFrame(m_pCapture);
      QImage textureImage= IplImage2QImage(iplImage);
      GLC_Texture* pTexture= GLC_Factory::instance()->createTexture(textureImage);
      m_pTexturedMaterial->setTexture(pTexture);
      updateGL();
   }
}

:D
@+

Laurent Ribon


Mon Mar 07, 2011 7:32 pm
Profile

Joined: Fri Mar 12, 2010 9:24 am
Posts: 6
Post Re: Using OpenCV webcam video capture movie
Hi Laurent,

To get further, we can imagine to control all camera motions with OpenCV like Kinect does. When will you add tis feature to your GLC_Player??? ;) A part of the work was already made by Plagita (http://www.youtube.com/watch?v=vCYuCJ5ecKw)

I tried OpenCV last year for a home-made software and I found it very pleasant to use. Possibilities with GLC_Player could be insane.

Garibaldi

PS : Congrats for your great South Style :D


Fri Mar 11, 2011 9:57 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.