RSS
 

Archive for the ‘OpenCV’ Category

OpenCV: Converting an image to gray scale

11 Jun

This is an easy way to convert 3 channel image which means color image:

// convert to gray scale
IplImage* img_gray = cvCreateImage( cvSize(img_rgb->width, img_rgb->height), IPL_DEPTH_8U, 1 );
cvCvtColor( img_rgb, img_gray, CV_BGR2GRAY );

The standard color sapce in OpenCV is BGR.

 
2 Comments

Posted in OpenCV

 

OpenCV: The cross correlation of two opencv images

11 Jun

This function calculates the cross correlation between two images of the type IplImage*. Returns the resulting value.

double cross_correlation( IplImage* img1, IplImage* img2 ){
  double corr;

  int M = img1->width;
  int N = img1->height;

  BwImage img_1( img1 ); // using opencv wrapper for accessing image pixels
  BwImage img_2( img2 );

  CvScalar img1_avg = cvAvg( img1, NULL );
  CvScalar img2_avg = cvAvg( img2, NULL );

  double sum_img1_img2 = 0;
  double sum_img1_2 = 0;
  double sum_img2_2 = 0;

  for( int m=0; m<m ; ++m ){
   for( int n=0; n<n; ++n ){
    sum_img1_img2   = sum_img1_img2 + (img_1[m][n]-img1_avg.val[0])*(img_2[m][n]-img2_avg.val[0]);
    sum_img1_2      = sum_img1_2 + (img_1[m][n]-img1_avg.val[0])*(img_1[m][n]-img1_avg.val[0]);
    sum_img2_2      = sum_img2_2 + (img_2[m][n]-img2_avg.val[0])*(img_2[m][n]-img2_avg.val[0]);
    }
  }

  corr = sum_img1_img2/sqrt(sum_img1_2*sum_img2_2);

  return corr;
}
 
7 Comments

Posted in OpenCV

 

OpenCV: Phase Correlation

11 Jun

The phase correlation method is very useful when we need to compare the similarities of two or more images. While looking in the internet I fount this interesting page.

 
No Comments

Posted in OpenCV

 

OpenCV: Implementation of Eigenface

10 Jun

I found a good tutorial which explain how the face recognition method called eigenface works: Cognotics
This tutorial uses the deprecated function cvCalcEigenObjects().
The advised function is cvCalcPCA().


 
No Comments

Posted in C++, OpenCV