Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

image moment normalization

I am doing a sign language to voice recognition ,i am using normalized moments to compare databse images and captured frame , moments are used to calculate the orientation of the image and rotate it so that between orientation and reference angle there's a 5 degree difference ,i am following the method in this thesis link text more explaination of normalizarion is from page 28 to 30 .

The problem is when i am trying to implement the code the results are as follows inputapplying contrast and thresholding first rotation and flipping !second rotation3rd rotation

when trying to compare the final result with an image captured by subtracting pixels and defining a threshold value of 80 percent , only input images which are the same give the correct answer , so the problem is in the normalization part but i can't identify how to improve it

this is the normalization method ::


   int normalize2 (const char * imageDB) 
{ 
FILE *fp; 
IplImage* pic1=0 , *pic2=0 , *tempT=0, *tempDB=0 , *temp3=0 , *temp4=0; 
double u11 , u20 , u02 , theta1=0 , compare=0, theta2=0 , theta3=0 , theta=0, ratio=0; 
//int h= 100 , w= 100 ;          // Parameters needed for rotation 
int a=0 , bright=0 , pixel1 =0 , pixel2 =0; 
int threshold = 80 , id=0 , i=0; 
CvMoments moments; 


cvNamedWindow("Tobe_Modified",1); 
cvMoveWindow( "Tobe_Modified", 0, 50); 
cvNamedWindow("final",1); 
cvMoveWindow( "final", 500, 50); 
cvNamedWindow("compare",1);
cvMoveWindow( "compare", 250, 400);


 imageDB="hand.jpg";   

const char * name=0; 

pic2 = cvLoadImage(imageDB,0); 
tempDB = cvCreateImage( cvGetSize(pic2), IPL_DEPTH_8U, 1 ); 
tempDB = cvLoadImage(imageDB,0); 
//cvResize(tempT,tempDB, CV_INTER_AREA);  // Normalize SIZE to standard size of Temp2
int w= cvGetSize(pic2).width/2;    //Set rotation axes from size of image 
int h=cvGetSize(pic2).height/2;


cout<<"widthis"<<w<<"heght is "<<h<<endl;

cvSmooth(tempDB,tempDB,CV_GAUSSIAN,1,1);
ContrastBrightness(tempDB,40,10);
cvThreshold(tempDB,tempDB,100,255,CV_THRESH_BINARY);
cvSaveImage("afternorm.jpg",tempDB);
int f= cvCountNonZero(tempDB);
cout<<f<<"Non Zero Pixels in TEST"<<endl;
GetRotatedImage(tempDB,0,h,w);

cout<<"done first rotation\n"<<endl;

cvSaveImage("FirstRotation.jpg",tempDB);

cvFlip(tempDB,tempDB);
theta1=0;
cout<<"Angle of first image "<<theta1<<endl;

cvShowImage("Tobe_Modified",tempDB);
cvMoments( tempDB, &moments, 1 );   

u11=cvGetCentralMoment( &moments, 1,1 ); 
u20=cvGetCentralMoment( &moments, 2,0 ); 
u02=cvGetCentralMoment( &moments, 0,2 ); 
/////////////////////////////////////// EQ 1 //////////////////////////////////////////////////
theta=2*u11/(u20-u02); 

cout <<" The ANGLE theta in radians  = " <<theta <<endl; 
theta = 180*theta/pi;
cout <<" The ANGLE theta in degree  = " <<theta <<endl; 

if ((theta >=0) & (theta <=pi)) {
//Page 65of 83 
theta2 = 0.5*atan(2*u11/(u20-u02));
cout<<"1"<<endl;
cout<<theta2<<"theta2 in radians in 1st cond"<<endl;
}
else {
if ((theta > pi) & (theta < 1.5*pi)) {
    cout<<"2"<<endl;
    theta2 = 0.5*(atan(2*u11/(u20-u02)) + pi);
cout<<theta2<<"theta2 in radians in 2nd cond"<<endl;
}
else{ 
    cout<<"3"<<endl;
theta2 = 0.5*(atan(2*u11/(u20-u02))+2*pi) ; 
cout<<theta2<<"theta2 in radians in 3rd cond"<<endl;
 }

}
theta2 = 180*theta2/pi;
cout <<"angle theta2 of secnod image in degrees = " <<theta2 <<endl; 


while ( (theta2-theta1 > 3 || theta2-theta1 <- 3) & (a < 360) || (theta1>0) & 
(theta2<0) || (theta1<0) & (theta2>0)) 
{ 
    printf("error b4 2nd rota \n");
tempDB=GetRotatedImage(tempDB, a, h, w); 
printf("done seond rotation\n");
cvSaveImage("secondRotation.jpg",tempDB);
cvMoments( tempDB, &moments, 4 ); 
u11=cvGetCentralMoment( &moments, 1,1 ); 
u20=cvGetCentralMoment( &moments, 2,0 ); 
u02=cvGetCentralMoment( &moments, 0,2 ); 
theta=2*u11/(u20-u02); 
cout <<"angle theta after second rotation  in degree= " <<180*theta/pi<<endl; 
if ((theta >=0) & (theta <=pi)) 
theta2 = 0.5*atan(2*u11/(u20-u02)); 
else 
if ((theta > pi) & (theta < 1.5*pi)) 
theta2 = 0.5*(atan(2*u11/(u20-u02)) + pi); 
else 
theta2 = 0.5*(atan(2*u11/(u20-u02))+2*pi) ; 
cout <<"angle theta2 after second rotation  in degree= " <<180*theta2/pi<<endl; //(rotate) image during normalizing 
a=a+3; 
theta2=180*theta2/pi; 
} 
tempDB=GetRotatedImage(tempDB, a-3, h, w); 
cvSaveImage("3rdRotation.jpg",tempDB);
cout <<"Pixel1 =" <<pixel1 <<endl; 
cout <<"Pixel2 =" <<pixel2 <<endl; 
cout <<cvGetSize(tempDB).width <<endl ; 
cout <<a-3<<" done" <<endl; 
cout <<cvGetSize(tempDB).width/2 <<" done" <<endl; 
cvShowImage("final",tempDB); 
//cvWaitKey(0);

name = "handT.jpg"; 
char * z = "f" ;
cout << " ((here about to compare normalized "<<endl;
 name = "hand.jpg" ;
compare=compare2(tempDB,name); 

if (compare > threshold ) { //Setting threshold to be 80% 
    id = 1; 
}
cout <<compare <<"  ::compare norm ? "<<endl;
cout <<id<<"  ::id if 1 then true "<<endl;

return id ;

}