4/26/2012

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




4/02/2012

The source code to get joystick input value(C++,MFC)

My Environment : MS VS 2008 & MFC(Dialog Based)
Joy Stick : Logitech Extreme 3D pro (XBox Type)
Cteated Date : 2012. 03
[source code]





We use dxShow to get joystick input value.
So we need these files "mmsystem.h", "winmm.lib", "winmm.dll". But normally, there are already in your computer.

The method to get value of joystick is very easy.
First, to confirm whether the joystick is connected well or not. And calibrate range by control pannel in window.

Second, cording~
#include "mmsystem.h"

JOYINFOEX joyInfoEx;
 joyInfoEx.dwSize = sizeof(joyInfoEx);
 joyGetDevCaps(JOYSTICKID1, &joyCaps, sizeof(joyCaps));
 JoyPresent = (joyGetPosEx(JOYSTICKID1, &joyInfoEx) == JOYERR_NOERROR);

JOYINFOEX joyInfoEx;
 if (JoyPresent)
 {
  joyInfoEx.dwSize = sizeof(joyInfoEx);
  joyInfoEx.dwFlags = JOY_RETURNALL;
  joyGetPosEx(JOYSTICKID1, &joyInfoEx);
 }

//And you can confirm button click and stick moving value

 if (joyInfoEx.dwButtons & 0x1) //then do whatever
 {
  str.Format("button1");
  m_ListBox2.AddString(str);
 }

 if (joyInfoEx.dwButtons & 0x2) //then do whatever
 {
  str.Format("button2");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x4) //then do whatever
 {
  str.Format("button3");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x8) //then do whatever
 {
  str.Format("button4");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x10) //then do whatever
 {
  str.Format("button5");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x20) //then do whatever
 {
  str.Format("button6");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x40) //then do whatever
 {
  str.Format("button6");
  m_ListBox2.AddString(str);
 }
 if (joyInfoEx.dwButtons & 0x80) //then do whatever
 {
  str.Format("button6");
  m_ListBox2.AddString(str);
 }


if ( joyInfoEx.dwPOV == 0 )
 {
  str.Format("Up");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 4500){
  str.Format("Up+Right");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 9000){
  str.Format("Right");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 13500){
  str.Format("Down+Right");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 18000){
  str.Format("Down");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 22500){
  str.Format("Down+Left");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 27000){
  str.Format("Left");
  m_ListBox2.AddString(str);
 }else if( joyInfoEx.dwPOV == 31500){
  str.Format("Up+Left");
  m_ListBox2.AddString(str);
 }if ( joyInfoEx.dwPOV & 0x1 ){
  str.Format("No Input");
  m_ListBox2.AddString(str);
 }

str.Format("X:%d Y:%d Z:%d", joyInfoEx.dwXpos, joyInfoEx.dwYpos, joyInfoEx.dwZpos);  m_ListBox.AddString(str); str.Format("R:%d U:%d V:%d", joyInfoEx.dwRpos, joyInfoEx.dwUpos, joyInfoEx.dwVpos);  m_ListBox3.AddString(str);


Thank you~
Everybody Fighting !!!

(TIP) ListBox contents count limit to prevent memory overflow and to show the latest list

(TIP) ListBox contents count limit to prevent memory overflow and to show the latest list

int nCount = m_ListBox1.GetCount();
//Contents count limit
if(nCount > 1000)
     m_ListBox1.ResetContent();

//To view the last content
if ( nCount > 0 )
     m_ListBox1.SetCurSel( nCount-1 );

2/29/2012

Pattern Image for Camera Calibration


[ Download Pattern.pdf ]

To convert from MyVisionUSB to OpenCV and Display (source code)



This is sample source to convert MyVision USB to OpenCV.
You need MyVision USB library to handle image buffer.

This link is included "MVULib.lib, MVULib.dll, MyVision.h".
Lib Download
And you can download driver file on the http://withrobot.com/157.


The below source is sample code to convert MyVision USB to OpenCV.
This code don't use memcpy. so it is little bit slow. The code needs upgrade to speed up.

#include < stdio.h >
#include < cv.h >
#include < cxcore.h >
#include < highgui.h >
#include < cvaux.h >
#include "MyVision.h"

using namespace std;

void main()
{

 //////////////////////////////////////////////////
 //MyVisionUSB Setting
 HBUF m_hBuf;
 HDIG m_hDig;
 char* ver = sysGetLibVer();
 if(strcmp(ver, MV_LIB_VER) != 0)
  printf("incorrect library version\n");
 m_hBuf = bufAlloc(640,480, MV_RGB32 | MV_DOUBLE);
 if(!m_hBuf)
  printf("Cann't Alloc Buffer\n");
 m_hDig = digAlloc(MV_DEV0);
 if(!m_hDig)
  printf("Cann't Alloc Digitizer");
 digGrabContinuous(m_hDig, m_hBuf);
 RGB32_T** pixel = (RGB32_T**)bufGetPtr2D(m_hBuf);
 ////////////////////////////////////////////////////



 //////////////////////////////////////////////////////////////////////////
 //OpenCV Setting
 cvNamedWindow("MyVisionUSBtoOpenCV",CV_WINDOW_AUTOSIZE);
 IplImage * img = cvCreateImage(cvSize(640,480), 8, 3);


 int color, R, G, B, c; 
 while(1)
 {  
  digGrabWait(m_hDig, MV_FIELD_EVEN);

  for(int i=0; i<480 color="color" for="for" i="i" int="int" j="j" r="RGB32_TO_R(color);" xff0000="xff0000">>16);
    G = RGB32_TO_G(color);  // (((color)&0x00ff00)>>8);
    B = RGB32_TO_B(color);  // (((color)&0x0000ff));

    img->imageData[i*img->widthStep+j*3+0] = B;
    img->imageData[i*img->widthStep+j*3+1] = G;
    img->imageData[i*img->widthStep+j*3+2] = R;
   }
  }

  cvShowImage("MyVisionUSBtoOpenCV",img);    
  if( cvWaitKey(10) > 0 )
   break;
 }


 //////////////////////////////////////////////////////////////////////////
 //release memory
 cvReleaseImage(&img);
 cvDestroyAllWindows();
 //
 digHalt(m_hDig);
 digFree(m_hDig);
 bufFree(m_hBuf);


}





2/24/2012

Open Cv with Ip Camera (AXIS)

If your Ip camera production is AXIS, download Axis media control sdk on the this web page
http://www.axis.com/techsup/cam_servers/dev/activex.htm
And Install.

Add the axis control on you dlg box.
You can make the AxisMediaControl icon by choose items(right button click on the toolbox menu)->com components tap.
And add the AxisMediaControl on you dlg.

Plase refer to below video clip description of the rest steps. It is very useful video clip.
http://www.youtube.com/watch?v=g6lYJBABWRs&feature=player_detailpage


I am writing left article...