4/26/2012

(TIP) Be careful when you use this type "unsigned long long type"


Firstly, refer to this webpage(http://stackoverflow.com/questions/2844/how-do-you-printf-an-unsigned-long-long-int)


unsigned long long -> %llu

When you use this type -> unsigned long long llType;
You have to be careful when you use :printf, fprintf, sprintf...
you have to use "%llu".
ex) printf("%llu", llType);

Or, You will meet this problem.

Source:
unsigned long long int num = 285212672; 
int normalInt = 5;      
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);

Output : 
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.




I takes about 2hours to solve this problem...





(TIP) C++ Make folder (CreateDirectory)


The method to create folder is esay.
You can do this jop using window api.

this is sample code for making folder

//make path string 
char buf[MAX_PATH];
DWORD dir = GetCurrentDirectory(MAX_PATH, buf);
CString directory = buf;
directory += "\\New_Folder";

//make folder
if(!CreateDirectory(directory,NULL))
//check error
         switch (GetLastError()) {
           case ERROR_ALREADY_EXISTS: //Folder exists
 break;
     default:
 ;
}
//end ^^

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);