4/25/2012

Convert from FlyCapture(Point grey) to OpenCV (Source code)

Convert from FlyCapture(Point grey) to OpenCV (Source code)

My environment :
FlyCapture 2.x
OpenCV 2.3
VS 2010


This source code is referred to this site (in korean).

*You have to set to use flycapture lib.

-Firstly, set "include, lib" directory on your vs studio.
I have set this path to my vs option.
"C:\Program Files (x86)\Point Grey Research\FlyCapture2\include"
"C:\Program Files (x86)\Point Grey Research\FlyCapture2\lib"

-Second, set Additional Dependencies on project property.
Add these libs
"flycapture2.lib FlyCapture2GUI.lib"

-Third, include this header file on your source code.
#include "FlyCapture2.h"
#include "FlyCapture2GUI.h"


Below source code is core part to convert flycaptuer to opencv.
This part is included in the linked surce code.
In detail, please refer to my source code.

Thank you.

[source code]




// Camera GUID acquisition 카메라 GUID νšλ“
 m_error = m_BusManager.GetCameraFromIndex(0,&m_Guid);
 // Camera connection 카메라 μ—°κ²°
 m_error = m_Cam.Connect(&m_Guid);
 // Grap start μ˜μƒ νšλ“ μ‹œμž‘
 m_error = m_Cam.StartCapture();

 m_pDC=GetDC();
 m_pDC->SetStretchBltMode(COLORONCOLOR);
 m_bitmapInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
 m_bitmapInfo.bmiHeader.biPlanes=1;
 m_bitmapInfo.bmiHeader.biCompression=BI_RGB;
 m_bitmapInfo.bmiHeader.biXPelsPerMeter=100;
 m_bitmapInfo.bmiHeader.biYPelsPerMeter=100;
 m_bitmapInfo.bmiHeader.biClrUsed=0;
 m_bitmapInfo.bmiHeader.biClrImportant=0;
 m_bitmapInfo.bmiHeader.biBitCount=24;
 m_bitmapInfo.bmiHeader.biSizeImage=0;


 while(m_ThreadContinue)
 {
  m_error = m_Cam.RetrieveBuffer(&m_Image);

  // convert to RGB type νšλ“ν•œμ˜μƒRGB ν˜•νƒœλ‘œλ³€ν™˜
  m_error = m_Image.Convert(PIXEL_FORMAT_BGR, &m_ImageColor);

  if( CvImg == NULL)
   CvImg = cvCreateImage(cvSize(m_ImageColor.GetCols(),m_ImageColor.GetRows()),8,3);
  memcpy(CvImg->imageDataOrigin,m_ImageColor.GetData() ,m_ImageColor.GetCols()*m_ImageColor.GetRows()*3);
  
  /*
  //Simple Processing
  for(int i=0; iheight; ++i)
  {
   for(int j=0; jwidth; ++j)
   {
    CvImg->imageData[i*CvImg->widthStep+j*3+2] = 255 - CvImg->imageData[i*CvImg->widthStep+j*3+2];
    CvImg->imageData[i*CvImg->widthStep+j*3+1] = 255 - CvImg->imageData[i*CvImg->widthStep+j*3+1];
    CvImg->imageData[i*CvImg->widthStep+j*3+0] = 255 - CvImg->imageData[i*CvImg->widthStep+j*3+0];
   }
  }
  */

  m_bitmapInfo.bmiHeader.biWidth=m_Image.GetCols();
  m_bitmapInfo.bmiHeader.biHeight=-m_Image.GetRows();  
  StretchDIBits(m_pDC->GetSafeHdc(),0,0,320,240,0,0,m_ImageColor.GetCols(),m_ImageColor.GetRows(),CvImg->imageDataOrigin,&m_bitmapInfo,DIB_RGB_COLORS,SRCCOPY);
 }

 
 ReleaseDC(m_pDC);
 SetEvent(m_heventThreadDone);




3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This looks cool. When I finally get my camera I will have to test this out.

    ReplyDelete
  3. Thank You.. First code for a long time that works for my camera chameleon3.

    ReplyDelete