12/26/2012

My first Arduino art (5led on/off example source)

The advantage of Arduino is beginners can access electrical and electronic experiment easily.
I think the reason is the arduino support abundant examples  and functions.
Nervertheless I don't know ATmega, I could led on/off easily.

This is demo video and picture.
To experiment my case, you need arduino board, resistance 220om and led.

And to setup your arduino is explained very well on the homepage.
http://arduino.cc/en/Guide/HomePage
http://arduino.cc/en/Guide/Windows





Thank you.



source code
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int mode=0;
int order=1;
int count=0;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led-1,OUTPUT); 
  pinMode(led-2,OUTPUT);
  pinMode(led-3,OUTPUT);
  pinMode(led-4,OUTPUT);
      
}

// the loop routine runs over and over again forever:
void loop() { 

  if(mode == 0)
    count = count+1;
  else
    count = count-1;

  for(int i=0; i< 5 i=i+1) {
    if(count%5 == i)
      digitalWrite(led-i, HIGH);   // turn the LED on (HIGH is the voltage level)     
    else
      digitalWrite(led-i, LOW);   // turn the LED on (HIGH is the voltage level)   
  }
  delay(200);

  if(mode == 0)
  {
    if(count == 50)     
      mode=1;
  }else{
    if(count == 0)
      mode=0;   
  } 
}

12/09/2012

Canny Edge - OpenCV Sample Code(example source)

// Origin Image
IplImage *pImage = cvLoadImage(“-”);

// Gray Image
IplImage *pGray = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_8U, 1 );

// RGB to Gray
cvCvtColor(pImage, pGray, CV_RGB2GRAY);

// Edge Image
IplImage *pEdge = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_8U, 1 );

// Canny Function
//Th1 is maximum value to Start tracking edge point
//If pixel point value is bigger than Th1, Edge connecting is started.

//Th2 is minimum value to stop tracking edge point
//If pixel point value is smaller than Th2, Edge connecting is ended.

cvCanny( pGray, pEdge, th1, th2 );

th1 = 10, th2=100

th1=200, th2=100










11/06/2012

YUV color format (444, 422, 411) - simple explanation

In the YUV color format, Y is bright information, U is blue color area, V is red color area.
Show the below picture. The picture is u-v color map

 
 
There are 3 type color format of YUV.
The types are 444, 422, 411.
 
 
444 is one pixel is 24 bits. 
 
 
 
 
422 is one pixel is 16 bits.
And U0, V0 is shared by Y0, Y1.



411 is one pixel is 12 bits.
 
 
 
 
This source code is convert code from YUV422 to RGB.
 

/ 


void ConvertYUV422toRGB(unsigned char** pSrc, unsigned char** pDst,int width,int height){
int i,j;
unsigned char* dst=*pDst;
unsigned char* src=*pSrc;
int Y1,Y2,U,V;
int R,G,B;

for(i=0;i2)
{
Y1=src[i*2+1];
Y2=src[i*2+3];
U=src[i*2];
V=src[i*2+2];

dst[i*3+2]=(unsigned char)((float)Y1+(1.4075f*(float)(V-128)));
dst[i*3+1]=(unsigned char)((float)Y1+(0.3455f*(float)(U-128)-(0.7169f*(float)(V-128))));
dst[i*3]=(unsigned char)((float)Y1+(1.7790f*(float)(U-128)));
dst[i*3+5]=(unsigned char)((float)Y2+(1.4075f*(float)(V-128)));
dst[i*3+4]=(unsigned char)((float)Y2+(0.3455f*(float)(U-128)-(0.7169f*(float)(V-128))));
dst[i*3+3]=(unsigned char)((float)Y2+(1.7790f*(float)(U-128)));
}
}

 


And YUV is converted by below fomulation.

R = Y + 1.4075(V-128)
G = Y - 0.3455(U-128) - 0.7169(V-128)
B = Y + 1.7790(U-128)
 
 
 
Thanks you.
 


sorry last source code is broken.
becasue html tag..
So I upload new version convert source code.
note!!! check Y position, the position is different as machine environment..
In the source code, stride means real width size.
YUV422 to RGB
--
//yuv to rgb
 int Y,U,V;   
 int R1,G1,B1;
 for(int ih=0; ihm_height; ++ih)
 {   
  //int iww=0;
  for(int iw=0; iwm_width; iw++)
  {
  
   if(iw %2 == 0)
   {
    Y = obj->m_yuv[ih*obj->m_stride + iw*2 + 0];
    U = obj->m_yuv[ih*obj->m_stride + iw*2 + 1];
    V = obj->m_yuv[ih*obj->m_stride + iw*2 + 3];
   }else{
    Y = obj->m_yuv[ih*obj->m_stride + iw*2 + 0];
    U = obj->m_yuv[ih*obj->m_stride + iw*2 -1];
    V = obj->m_yuv[ih*obj->m_stride + iw*2 + 1];
   }
   
   R1 = Y + 1.4075*(V-128);
   G1 = Y - 0.3455*(U-128) - 0.7169*(V-128);
   B1 = Y + 1.7790*(U-128);

   o_Image2.at(ih, iw)[0] = BYTE(MMIN(255, MMAX(0, B1)));// B1;
   o_Image2.at(ih, iw)[1] = BYTE(MMIN(255, MMAX(0, G1)));// G1;
   o_Image2.at(ih, iw)[2] = BYTE(MMIN(255, MMAX(0, R1)));// R1;
  }
 }
--
RGB to YUV422
--
int Y,U,V;   
   int R1,G1,B1;
   for(int ih=0; ih< obj->m_height; ++ih)
   {   
    //int iww=0;
    for(int iw=0; iw< obj->m_width; iw++)
    {

     B1 = o_Image2.at< cv::Vec3b>(ih, iw)[0];// B1;
     G1 = o_Image2.at< cv::Vec3b>(ih, iw)[1];// G1;
     R1 = o_Image2.at< cv::Vec3b>(ih, iw)[2];// R1;

     Y = (0.257*R1) + (0.504*G1) + (0.098*B1) +16;
     U = -(0.148*R1) - (0.291*G1) + (0.439*B1) + 128;
     V = (0.439*R1 ) - (0.368*G1) - (0.071*B1) + 128;
     Y = MMIN(255, MMAX(0, Y));
     U = MMIN(255, MMAX(0, U));
     V = MMIN(255, MMAX(0, V));

     if(iw %2 == 0)
     {
      obj->m_yuv[ih*obj->m_stride + iw*2 + 0] = Y;
      obj->m_yuv[ih*obj->m_stride + iw*2 + 1] = U;
      obj->m_yuv[ih*obj->m_stride + iw*2 + 3] = V;
     }else{
      obj->m_yuv[ih*obj->m_stride + iw*2 + 0] = Y;
      obj->m_yuv[ih*obj->m_stride + iw*2 -1] = U;
      obj->m_yuv[ih*obj->m_stride + iw*2 + 1] = V;
     }     
    }
--
 


11/01/2012

clapack example source and method to use


clapack is math library to solve linear algebra in C language.
Originally, it is library to use in fortran language.
but clapack is made to use in C language.

1. You can see the method to use and file download on this site(http://icl.cs.utk.edu/lapack-for-windows/index.html)

Or

2. You can download pre-bulit clapack lib in here. I am using this lib now.
It might not run well, if the environment of your computer was different with me.
My environment is window 7 32bit, vs 2008.
The method to use is easy.
- Copy lib, header files in your project (The compressed file includes 'blas.lib, blasd.lib, lapack.lib, lapackd.lib, libf2c.lib, libf2cd.lib, clapack.h, f2c.h'.)
- Set Additional Dependencies on project property.
Add these libs "blas.lib lapack.lib libf2c.lib"
- include this header file on your source code.
#include "f2c.h"
#include "clapack.h"
- use functions of lapack.


this is example source code.
/*
    DGESV Example.
    ==============
  
    The program computes the solution to the system of linear
    equations with a square matrix A and multiple
    right-hand sides B, where A is the coefficient matrix:
  
      6.80  -6.05  -0.45   8.32  -9.67
     -2.11  -3.30   2.58   2.71  -5.14
      5.66   5.36  -2.70   4.35  -7.26
      5.97  -4.44   0.27  -7.17   6.08
      8.23   1.08   9.04   2.14  -6.87
 
   and B is the right-hand side matrix:
  
      4.02  -1.56   9.81
      6.19   4.00  -4.09
     -8.22  -8.67  -4.57
     -7.57   1.75  -8.61
     -3.03   2.86   8.99
  
    Description.
    ============
  
    The routine solves for X the system of linear equations A*X = B,
    where A is an n-by-n matrix, the columns of matrix B are individual
    right-hand sides, and the columns of X are the corresponding
    solutions.
 
   The LU decomposition with partial pivoting and row interchanges is
    used to factor A as A = P*L*U, where P is a permutation matrix, L
    is unit lower triangular, and U is upper triangular. The factored
    form of A is then used to solve the system of equations A*X = B.
 
   Example Program Results.
    ========================
  
  DGESV Example Program Results
 
 Solution
   -0.80  -0.39   0.96
   -0.70  -0.55   0.22
    0.59   0.84   1.90
    1.32  -0.10   5.36
    0.57   0.11   4.04
 
 Details of LU factorization
    8.23   1.08   9.04   2.14  -6.87
    0.83  -6.94  -7.92   6.55  -3.99
    0.69  -0.67 -14.18   7.24  -5.19
    0.73   0.75   0.02 -13.82  14.19
   -0.26   0.44  -0.59  -0.34  -3.43
 
 Pivot indices
       5      5      3      4      5
 */

#include 
#include 

#include "f2c.h"
#include "clapack.h"


 extern void print_matrix( char* desc, int m, int n, double* a, int lda );
 extern void print_int_vector( char* desc, int n, int* a );
 
/* Parameters */
 #define N 5
 #define NRHS 3
 #define LDA N
 #define LDB N
 
/* Main program */
 int main() {
         /* Locals */
         integer n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info;
         /* Local arrays */
         integer ipiv[N];
         double a[LDA*N] = {
             6.80, -2.11,  5.66,  5.97,  8.23,
            -6.05, -3.30,  5.36, -4.44,  1.08,
            -0.45,  2.58, -2.70,  0.27,  9.04,
             8.32,  2.71,  4.35, -7.17,  2.14,
            -9.67, -5.14, -7.26,  6.08, -6.87
         };
         double b[LDB*NRHS] = {
             4.02,  6.19, -8.22, -7.57, -3.03,
            -1.56,  4.00, -8.67,  1.75,  2.86,
             9.81, -4.09, -4.57, -8.61,  8.99
         };
         /* Executable statements */
         printf( " DGESV Example Program Results\n" );
         /* Solve the equations A*X = B */
         dgesv_( &n, &nrhs, a, &lda, ipiv, b, &ldb, &info );
         /* Check for the exact singularity */
         if( info > 0 ) {
                 printf( "The diagonal element of the triangular factor of A,\n" );
                 printf( "U(%i,%i) is zero, so that A is singular;\n", info, info );
                 printf( "the solution could not be computed.\n" );
                 exit( 1 );
         }
         /* Print solution */
         print_matrix( "Solution", n, nrhs, b, ldb );
         /* Print details of LU factorization */
         print_matrix( "Details of LU factorization", n, n, a, lda );
         /* Print pivot indices */
         print_int_vector( "Pivot indices", n, (int*)ipiv );
         exit( 0 );
 } /* End of DGESV Example */
 
/* Auxiliary routine: printing a matrix */
 void print_matrix( char* desc, int m, int n, double* a, int lda ) {
         int i, j;
         printf( "\n %s\n", desc );
         for( i = 0; i < m; i++ ) {
                 for( j = 0; j < n; j++ ) printf( " %6.2f", a[i+j*lda] );
                 printf( "\n" );
         }
 }
 
/* Auxiliary routine: printing a vector of integers */
 void print_int_vector( char* desc, int n, int* a ) {
         int j;
         printf( "\n %s\n", desc );
         for( j = 0; j < n; j++ ) printf( " %6i", a[j] );
         printf( "\n" );


 }





This site is useful to know what functions are exist. but there is not source code. http://www.calerga.com/doc/LME_lapk.htm This site is very useful, there are descriptions and  example source codes. http://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/index.htm#dgesv.htm












10/25/2012

Inner product(the angle between the two lines) - function source code




If there are 3 point(c, p1, p2), as shown in the above figure.
This function got the angle between the two lines using inner product.
Even if the name changed from (p1, p2) to (p2, p1),  the function get the narrow angle between the two lines.

I hope this code useful to you.
thank you.


float innerAngle(float px1, float py1, float px2, float py2, float cx1, float cy1)
{

 float dist1 = sqrt(  (px1-cx1)*(px1-cx1) + (py1-cy1)*(py1-cy1) );
 float dist2 = sqrt(  (px2-cx1)*(px2-cx1) + (py2-cy1)*(py2-cy1) );

 float Ax, Ay;
 float Bx, By;
 float Cx, Cy;

 //find closest point to C
 //printf("dist = %lf %lf\n", dist1, dist2);

 Cx = cx1;
 Cy = cy1;
 if(dist1 < dist2)
 {  
  Bx = px1;
  By = py1;  
  Ax = px2;
  Ay = py2;


 }else{
  Bx = px2;
  By = py2;
  Ax = px1;
  Ay = py1;
 }


 float Q1 = Cx - Ax;
 float Q2 = Cy - Ay;
 float P1 = Bx - Ax;
 float P2 = By - Ay;  


 float A = acos( (P1*Q1 + P2*Q2) / ( sqrt(P1*P1+P2*P2) * sqrt(Q1*Q1+Q2*Q2) ) );

 A = A*180/PI;

 return A;
}




10/23/2012

Optical Flow sample source code using OpenCV



Optical Flow sample source code using OpenCV.
It programed based on http://feelmare.blogspot.kr/2012/10/make-2-frame-having-time-interval-in.html source code for time difference frame.

#define MAX_COUNT 250   
#define DELAY_T 20   
#define PI 3.1415   


void main()   
{   

 //////////////////////////////////////////////////////////////////////////   
 //image class         
 IplImage* image = 0;   

 //T, T-1 image   
 IplImage* current_Img = 0;   
 IplImage* Old_Img = 0;   

 //Optical Image   
 IplImage * imgA=0;   
 IplImage * imgB=0;   


 //Video Load   
 CvCapture * capture = cvCreateFileCapture("1.avi"); //cvCaptureFromCAM(0); //cvCreateFileCapture("1.avi");   

 //Window   
 cvNamedWindow( "Origin" );   
 //////////////////////////////////////////////////////////////////////////   


 //////////////////////////////////////////////////////////////////////////    
 //Optical Flow Variables    
 IplImage * eig_image=0;
 IplImage * tmp_image=0;
 int corner_count = MAX_COUNT;   
 CvPoint2D32f* cornersA = new CvPoint2D32f[ MAX_COUNT ];   
 CvPoint2D32f * cornersB = new CvPoint2D32f[ MAX_COUNT ];   

 CvSize img_sz;   
 int win_size=20;   

 IplImage* pyrA=0;   
 IplImage* pyrB=0;   

 char features_found[ MAX_COUNT ];   
 float feature_errors[ MAX_COUNT ];   
 //////////////////////////////////////////////////////////////////////////   


 //////////////////////////////////////////////////////////////////////////   
 //Variables for time different video   
 int one_zero=0;   
 int t_delay=0;   



 //Routine Start   
 while(1) {      


  //capture a frame form cam      
  if( cvGrabFrame( capture ) == 0 )   
   break;   

  //Image Create   
  if(Old_Img == 0)      
  {      
   image = cvRetrieveFrame( capture );   
   current_Img = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);      
   Old_Img  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);

   

  }   



  if(one_zero == 0 )   
  {   
   if(eig_image == 0)
   {
    eig_image = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);
    tmp_image = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);
   }

   //copy to image class   
   memcpy(Old_Img->imageData, current_Img->imageData, sizeof(char)*image->imageSize );   
   image = cvRetrieveFrame( capture );   
   memcpy(current_Img->imageData, image->imageData, sizeof(char)*image->imageSize );   

   //////////////////////////////////////////////////////////////////////////   
   //Create image for Optical flow   
   if(imgA == 0)   
   {   
    imgA = cvCreateImage( cvSize(image->width, image->height), IPL_DEPTH_8U, 1);   
    imgB = cvCreateImage( cvSize(image->width, image->height), IPL_DEPTH_8U, 1);       
   }      

   //RGB to Gray for Optical Flow   
   cvCvtColor(current_Img, imgA, CV_BGR2GRAY);   
   cvCvtColor(Old_Img, imgB, CV_BGR2GRAY);      

   //   
   cvGoodFeaturesToTrack(imgA, eig_image, tmp_image, cornersA, &corner_count, 0.01, 5.0, 0, 3, 0, 0.04);   
   cvFindCornerSubPix(imgA, cornersA, corner_count, cvSize(win_size, win_size), cvSize(-1, -1), cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 20, 0.03));      


   CvSize pyr_sz = cvSize( imgA->width+8, imgB->height/3 );   
   if( pyrA == 0)   
   {    
    pyrA = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1);   
    pyrB = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1);   
   }   

   cvCalcOpticalFlowPyrLK( imgA, imgB, pyrA, pyrB, cornersA, cornersB, corner_count, cvSize(win_size, win_size), 5, features_found, feature_errors, cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.3), 0);   

   /////////////////////////////////////////////////////////////////////////      

   for(int i=0; i< corner_count; ++i)
   {

    if( features_found[i] == 0 || feature_errors[i] > MAX_COUNT )
     continue;   



    //////////////////////////////////////////////////////////////////////////       
    //Vector Length   
    float fVecLength = sqrt((float)((cornersA[i].x-cornersB[i].x)*(cornersA[i].x-cornersB[i].x)+(cornersA[i].y-cornersB[i].y)*(cornersA[i].y-cornersB[i].y)));   
    //Vector Angle   
    float fVecSetha  = fabs( atan2((float)(cornersB[i].y-cornersA[i].y), (float)(cornersB[i].x-cornersA[i].x)) * 180/PI );   

    cvLine( image, cvPoint(cornersA[i].x, cornersA[i].y), cvPoint(cornersB[i].x, cornersA[i].y), CV_RGB(0, 255, 0), 2);     

    printf("[%d] - Sheta:%lf, Length:%lf\n",i , fVecSetha, fVecLength);   
   }


   //////////////////////////////////////////////////////////////////////////       

  }   
  cvShowImage( "Origin", image );   

  //////////////////////////////////////////////////////////////////////////   

  //time delay   
one_zero++;
  if( (one_zero % DELAY_T ) == 0)   
  {      
   one_zero=0;   
  }   

  //break      
  if( cvWaitKey(10) >= 0 )      
   break;      
 }      

 //release capture point      
 cvReleaseCapture(&capture);   
 //close the window      
 cvDestroyWindow( "Origin" );      

 cvReleaseImage(&Old_Img);    
 //////////////////////////////////////////////////////////////////////////   
 cvReleaseImage(&imgA);   
 cvReleaseImage(&imgB);    
 cvReleaseImage(&eig_image);
 cvReleaseImage(&tmp_image);
 delete cornersA;   
 delete cornersB;    
 cvReleaseImage(&pyrA);   
 cvReleaseImage(&pyrB);   


 //////////////////////////////////////////////////////////////////////////   
}   





Thank you.

10/17/2012

Make 2 frame having time interval in video using OpenCV(Example source code)

This code is example source code that made 2 frame having time interval.
For example : this code made 2 images t time and t-x time in video stream.


This images shows origin image(Left), T time Image(center), T-x time Image(right)



This is example source code
You can control time delay frame using DELAY_T macro variable.

#define DELAY_T 30

void main()
{

  //image class      
    IplImage* image = 0;   
 IplImage* image1 = 0;    
 IplImage* image2 = 0;    

 
    //camera point   
 CvCapture * capture = cvCreateFileCapture("RunF.avi"); //cvCaptureFromCAM(0); //cvCreateFileCapture("1.avi");

 //make window   
 cvNamedWindow("Origin");
    cvNamedWindow( "t");  
 cvNamedWindow( "t-1");   
   
    
 int one_zero=0;
    
    while(1) {   


  //capture a frame form cam   
        if( cvGrabFrame( capture ) == 0)
   break;
  image = cvRetrieveFrame( capture );

  
  if(image2 == 0)   
        {   
   //image = cvRetrieveFrame( capture );
   image1  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);  
            image2  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);   
        }


  //show window   
  cvShowImage( "Origin", image);

  if(one_zero == 0 )
  {
   //copy to image class
   memcpy(image2->imageData, image1->imageData, sizeof(char)*image->imageSize );
   //image = cvRetrieveFrame( capture );
   memcpy(image1->imageData, image->imageData, sizeof(char)*image->imageSize );

   
   //show window   
   cvShowImage( "t", image1 );
   cvShowImage( "t-1", image2 );

  }

  //Time Delay
  one_zero++;
  if( (one_zero%DELAY_T) == 0)
  {   
   one_zero=0;
  }

 
        //break   
        if( cvWaitKey(10) >= 0 )   
            break;   
    }   
  
    
    //release capture point   
    cvReleaseCapture( &capture );

    //close the window   
    cvDestroyAllWindows();   

 //release Images
 cvReleaseImage(&image1);
 cvReleaseImage(&image2);

}

Thank you.


9/08/2012

Making thread on MFC (example source code)

Simple source code

//Declaration
static UINT Thread(LPVOID pParam);


//Definition
UINT Thread(LPVOID pParam)
{
     //Thread Part 
     while( ((GUIView*)pParam)->Thread_B )
    {
        //Time delay
        Sleep(100);

        //Processing
        ((GUIView*)pParam)->DoProcessing(); 
      }

      return 0;
}


//Thread Begin 
void GUIView::BegainThread()
{
     Thread_B = true;
     ::AfxBeginThread(Thread, this);
}

8/31/2012

My Copyright

//////////////////////////////////////////////////////////////////////////////////////////////
// Made by J.H.KIM, 2012.12.24 / feelmare@daum.net, feelmare@gmail.com  //
// My blog : http://feelmare.blogspot.com                                                 //
// My Lab : VISLAB(http://me.pusan.ac.kr)                                                //
// My Institute : Realhub RnD Cneter(http://www.realhub.co.kr                        //
/////////////////////////////////////////////////////////////////////////////////////////////

(source code)Camera Pan/Tilt using Servo motor, control by arduino

Download the Arduino software -> go to the page
Download usb driver -> go to the page

My environment is Window 7 64 bit.
Arduino version is Mega ADK.
If you are same equipment and window, download this file directly.
driver



8/28/2012

OpenGL 2 Views(windows) on MFC - Source code

It is a source code to make 2 views(windows) of openGL on MFC dialog.


Download this source code here.
This source code is applied by OpenGL Drawing test on MFC post on this site.

8/20/2012

source code - OpenGL Drawing on MFC dlg(using COpenGLControl class)

This  post introduces how to drawing opengl on the mfc dialog.
If we are using COpenGLControl class, this work is very easy and simple.

Fi rstly, get the COpenGLControl class in the web or on this.

1. In the ~Dlg.h, Add header file and member variable

#include "OpenGLControl.h"
~
COpenGLControl m_oglWindow;


2. Add below source code in the OnInitDialog() function.

CRect rect;
// Get size and position of the template textfield we created before in the dialog editor
GetDlgItem(IDC_PIC_OPENGL)->GetWindowRect(rect);
// Convert screen coordinates to client coordinates
ScreenToClient(rect);
// Create OpenGL Control window
m_oglWindow.oglCreate(rect, this);
// Setup the OpenGL Window's timer to render
m_oglWindow.m_unpTimer = m_oglWindow.SetTimer(1, 1, 0);


* You have to set picture box option as "Visible is False".


The source code is here.

8/06/2012

Contour compare using OpenCV(source code), cvFindContours, cvMatchShapes

There is shape match function in the OpenCV.
The function name is cvMatchShapes.
This function compares two contours.
If two contours is same, the function returns 0.
conversely, the value of return is larger, more shape different.
So, we use threshold to decide these pair is similar or not.


 






code start

code end

#findcontour, #contour, #compare


source coude

7/25/2012

Mesh Grid Tool, Surfer program

If you have x,y,z 3D point data. 
For example ..
X Y Z
1.22 2.22 3.22
1.322 6.22 2.22
1.42 3.22 1.22
1.522 1.22 4.22
1.22 3.22 2.22
...



I want to plot 3D surface in matlab.
But It is very hart because the data is too large. The number of data is 1176764.
And The interval of data is not regular.
So to make map(matrix) for plotting is very hard.
and even when I make map(matrix), Matlab did not work because 'out of memory'.

The method to solve is using sufer 9 tool.
We can get mesh grid easy.

The method to use..
Firstly, Get Surfer 9 program.

Second...
In the menu. Select Grid ->  Data
Choose your xyz.txt File.
And Open.


In Option window, normally there is no need to set up.
So just click 'OK'



Also 'OK'
then the tool will be working to make grid. After making grid, you can see report.
and then Open your grid file.
In menu, map -> new ->  3D wireframe



7/10/2012

(source code) points click on image and save the coordinate to txt file

environment: Visual C+++ 2008, openCV 2.3
 
This source code is to save the coordinate that you select points on image.
This is useful when you have many image to save coordinates.


Firstly, you should make image file name in number order.
0.jpg, 1.jpg 2.jpg .....


The code ask to you
1. How many file do you have ?
-
2. How many point do you click on image?
-


There are some keys.
Left button is point selection, Cancel is right button, Space key is next button.
and Ese is the button to finish the work.
After finish the work.

The coordinate is stored in "output.txt"
The format is that
x1 y1 x2 y2 x3 y3 x4 y4
x1 y1 x2 y2 x3 y3 x4 y4
x1 y1 x2 y2 x3 y3 x4 y4
x1 y1 x2 y2 x3 y3 x4 y4
...

[source code] 


Thanks you.






7/04/2012

full half face image data - 12,617(22 people)

full half face image data - 12,617(22 people)
100 x 100 image size
jpg file type

full half face image


frontal face image data - 13128(22 people)

frontal face image data - 13,128(22 people)
100x100 image size
jpg file type

frontal face data



face image data - half face 9580(22 people)

face image data - half face 9580(22 people)
jpg file type
100 x 100 image size

 half face 9580 ( 22 people )




7/03/2012

Frontal Face Image Data

4105 frontal faces.
bmp file type.
24x24 image size.
No margin face data.


Frontal face 4105(no margin)

5/17/2012

(TIP) If you meet error message 0xc000007b, Copy libguide40.dll file to your project folder.

I met the error message 0xc000007b, when I use openCV 1.0 in vs 2008.
The solution is that copy "libguide40.lib" file to your project folder.
I have solved by this mothod.

If you need "libguide40.dll", please contact me by email. I will send the file to you.
Thank you.

5/02/2012

Math Type 6.7


You can download MathType 6.7 from here.
If you need serial code , plz ask to my email.
Thank you.

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




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...

2/23/2012

(TIP) afxcontrolbars.h - No such file or directory Error!

If you meet this error message "afxcontrolbars.h - No such file or directory...", while complie on the VS C++.
You can solve this problem easily by installing Visual Studio Serviece Pack 1.0.

Download appropriate language version and install.

[vs90 sp1 English]
[vs90 sp1 Korea]

2/15/2012

(TIP) To get Color Information of specific pixel coordinate in the OpenGL

The method is simple to to get Color Information of specific pixel coordinate in the OpenGL is simple.
glReadPixels function enables these task.
The example source code is as follows.

struct{ GLubyte red, green, blue; } pixelColor;
glReadPixels(int(i), int(j), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixelColor);

But the drawback is too slow and we can get exact color information after view rendering.
Thanks.


2/09/2012

To Save OpenGL ViewPort to Image File (glReadPixels, OpenGL->OpenCV)


You can save the Viewport of OpenGL to Image file using glReadPixels function.
And this code is example for saving image file using openCV.
Thank you.

void CaptureViewPort()
{
 
 GLubyte * bits; //RGB bits
 GLint viewport[4]; //current viewport
  
 //get current viewport
 glGetIntegerv(GL_VIEWPORT, viewport);

 int w = viewport[2];
 int h = viewport[3];
 
 bits = new GLubyte[w*3*h];

 //read pixel from frame buffer
 glFinish(); //finish all commands of OpenGL
 glPixelStorei(GL_PACK_ALIGNMENT,1); //or glPixelStorei(GL_PACK_ALIGNMENT,4);
 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
 glReadPixels(0, 0, w, h, GL_BGR_EXT, GL_UNSIGNED_BYTE, bits);

 IplImage * capImg = cvCreateImage( cvSize(w,h), IPL_DEPTH_8U, 3);
 for(int i=0; i < h; ++i)
 {
  for(int j=0; j < w; ++j)
  {
   capImg->imageData[i*capImg->widthStep + j*3+0] = (unsigned char)(bits[(h-i-1)*3*w + j*3+0]);
   capImg->imageData[i*capImg->widthStep + j*3+1] = (unsigned char)(bits[(h-i-1)*3*w + j*3+1]);
   capImg->imageData[i*capImg->widthStep + j*3+2] = (unsigned char)(bits[(h-i-1)*3*w + j*3+2]);
  }
 }

 cvSaveImage("result.jpg",capImg); 
 cvReleaseImage(&capImg); 
 delete[] bits; 
 
}

2/07/2012

(TIP) Check the radio button control / MFC or API

[mfc case]
((CButton*)GetDlgItem(IDC_RADIO))->SetCheck(true);

[api case]
HWND hWnd;
hWnd = ::GetDlgItem(GetSafeHwnd(), IDC_RADIO_NOTIFY_ALL);
::CheckRadioButton(hWnd, IDC_RADIO_NOTIFY_ALL, IDC_RADIO_NOTIFY_CONTENTS, IDC_RADIO_NOTIFY_ALL);
::SendMessage(hWnd, BM_SETCHECK, (WPARAM)BST_CHECKED, NULL);

1/31/2012

Distance Tx, Ty according to Heading direction when you know the current point(x,y) - math note

Distance Tx, Ty according to Heading direction when you know the current point(x,y) - math note




Thank you~ ^^.

1/26/2012

(TIP) Maple 15 - The method of the Matrix multiply (3by3 Rotation matrix)

(TIP) Maple 15 - The method of the Matrix multiply

Show the below example~


or
We can use LinearAlgebra command. Using 'with(LinearAlgebra)' keyword
Show next example~



Thank you~ ^^

1/24/2012

(TIP) Maple 15 - the method of the matrix differential

(TIP) The method of the matrix differential in the Maple 15 math tool.
You should use "map" function. Show the below example.


Thanks you. ^^

1/10/2012

Sample source to make SubWindow in the OpenGL/ glutCreateSubWindow / Multi Window

This sample source is the method to make subwindow in the openGL programming.


The source may apply to your problem, because I have tried to make easy.
(Source Download)

#include "glut.h"
#include 
#include 

using namespace std;


#define GAP  25             /* gap between subwindows */
GLuint window, View1, View2, View3, View4;
GLuint sub_width = 256, sub_height = 256;

void main_display(void);
void main_reshape(int width,  int height);
void setfont(char* name, int size);
void drawstr(GLuint x, GLuint y, const char* format, int length);
GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_10;

void View1Display();
void View2Display();
void View3Display();
void View4Display();

void ResetViewport();

int main()
{
    //Mode Setting
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    //window size (+gap size)
    glutInitWindowSize(512+GAP*3, 512+GAP*3);
    //Initial position
    glutInitWindowPosition(50, 50);    

    //Main Window 
    window = glutCreateWindow("ViewPort Test");
    //Main Window callback function
    glutReshapeFunc(main_reshape);
    glutDisplayFunc(main_display);
    
    //World Window and Display
    View1 = glutCreateSubWindow(window, GAP, GAP, 256, 256);    
    glutDisplayFunc(View1Display);

    //screen Window and Display
    View2 = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256);
    glutDisplayFunc(View2Display);

    //command Window and Display
    View3 = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutDisplayFunc(View3Display);

    View4 = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutDisplayFunc(View4Display);


    glutMainLoop();

    return 0;
}

void main_display(void)
{
    //Background Color
    glClearColor(0.8, 0.8, 0.8, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //font color and style
    glColor3ub(0, 0, 0);
    setfont("helvetica", 12);

    //1st window name
    string str = "View1";
    drawstr(GAP, GAP-5, str.c_str(), str.length());

    //2st window name
    str = "View2";
    drawstr(GAP+sub_width+GAP, GAP-5, str.c_str(), str.length());

    //3st widnow name
    str = "View3";
    drawstr(GAP, GAP+sub_height+GAP-5, str.c_str(), str.length());

    //4st widnow name
    str = "View4";
    drawstr(GAP+sub_width+GAP, GAP+sub_height+GAP-5, str.c_str(), str.length());

    //last
    glutSwapBuffers();
}


//Background Window Setting
void main_reshape(int width,  int height) 
{
    //main view setting
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, width, height, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    sub_width = (width-GAP*3)/2.0;
    sub_height = (height-GAP*3)/2.0;

    //View1 Display
    glutSetWindow(View1);
    glutPositionWindow(GAP, GAP);
    glutReshapeWindow(sub_width, sub_height);

    //View2 Display
    glutSetWindow(View2);
    glutPositionWindow(GAP+sub_width+GAP, GAP);
    glutReshapeWindow(sub_width, sub_height);

    //View3 Display
    glutSetWindow(View3);
    glutPositionWindow(GAP, GAP+sub_height+GAP);
    glutReshapeWindow(sub_width, sub_height);


    //View4 Display
    glutSetWindow(View4);
    glutPositionWindow(GAP+sub_width+GAP, GAP+sub_height+GAP);
    glutReshapeWindow(sub_width, sub_height);
    //glutReshapeWindow(sub_width+GAP+sub_width, sub_height);    
}

//Font setting
void setfont(char* name, int size)
{
    font_style = GLUT_BITMAP_HELVETICA_10;
    if (strcmp(name, "helvetica") == 0) {
        if (size == 12) 
            font_style = GLUT_BITMAP_HELVETICA_12;
        else if (size == 18)
            font_style = GLUT_BITMAP_HELVETICA_18;
    } else if (strcmp(name, "times roman") == 0) {
        font_style = GLUT_BITMAP_TIMES_ROMAN_10;
        if (size == 24)
            font_style = GLUT_BITMAP_TIMES_ROMAN_24;
    } else if (strcmp(name, "8x13") == 0) {
        font_style = GLUT_BITMAP_8_BY_13;
    } else if (strcmp(name, "9x15") == 0) {
        font_style = GLUT_BITMAP_9_BY_15;
    }
}

//String Draw
void drawstr(GLuint x, GLuint y, const char* format, int length)
{
    glRasterPos2i(x, y);    
    for(int i=0; i        glutBitmapCharacter(font_style, *(format+i) );
}


//Display Teapot
void DrawScene()
{

    glColor3f(0.7, 0.7, 0.7);
    glPushMatrix();
    //glTranslatef(0.0, -1.0, 0.0);

    glBegin(GL_QUADS);
    glVertex3f(2.0, 0.0, 2.0);
    glVertex3f(2.0, 0.0, -2.0);
    glVertex3f(-2.0, 0.0, -2.0);
    glVertex3f(-2.0, 0.0, 2.0);
    glEnd();

    glPopMatrix();
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    glTranslatef(0.0, 0.0, -0.5);
    glutWireTeapot(1.0);
    glPopMatrix();

}

//View1Display
void View1Display(){

    
    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}

//View2Display
void View2Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}

//View3Display
void View3Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();
    gluLookAt(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);
    DrawScene();
    glPopMatrix();
    glutSwapBuffers();
}


//View4Display
void View4Display(){

    //viewport rest;
    ResetViewport();

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
        glLoadIdentity();
        gluPerspective(30, 1.0, 3.0, 50.0);
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
            gluLookAt(5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
            DrawScene();
        glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}


void ResetViewport()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0, 2.0, -2.0, 2.0, 0.5, 5.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}


1/05/2012

(Tip) tbb.dll error

If you meet the the tbb.dll error message box when you compile the project including openCV library.
You can slove this problem.

Go to this web page
http://threadingbuildingblocks.org/ver.php?fid=174
Download latest version, and unzip.

Open the makefile.sin as Visual studio, the makefile.sin is located in the "build\vsproject". And Compile.
Then you can get tbb.dll file in the release folder.

This is my compiled tbb.dll file.
download tbb.dll


My environment is Visual Studio 2008, openCv 2.3, Window 7.

Thank you.

1/04/2012

(Tip) Visual Studio Project Renamer Tool

Sometimes, we need to change the project name to other name.
Then this program is very useful.




Thank you.

1/03/2012

Partial differential method of Composite function and multivariate (Chain Rule #1, #2)

Chain Rule #1.



EX) When there are equations,



How to calculate differential about t?














Chain Rule #2









 

EX)





Another example
This example might adapt a problem of the Image optimazation.
 
 

I hope this post help you.
Thank you.