我正在使用openCV对语音进行手势识别,我正在使用瞬间来寻找手的方向,但是计算方向的结果对我来说并不足够有意义,所以我需要帮助理解它们。我也不知道以后该怎么办求图像的方向角。
查找方向角:
cvMoments( tempDB, &moments, 1 );
u11=cvGetCentralMoment( &moments, 1,1 );
u20=cvGetCentralMoment( &moments, 2,0 );
u02=cvGetCentralMoment( &moments, 0,2 );
cout<<moments.m00<<"moo"<<endl;
cout<<moments.m11<<"m11"<<endl;
cout<<moments.m02<<"m02"<<endl;
cout<<moments.m20<<"m21"<<endl;
/////////////////////////////////////// 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 <=45)) {
//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 > -45) & (theta < 0)) {
cout<<"2"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02));
cout<<theta2<<"theta2 in radians in 2nd cond"<<endl;
}
else{
if ((theta > 45) & (theta < 90)) {
cout<<"3"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02)) +( pi/2);
cout<<theta2<<"theta2 in radians in 3nd cond"<<endl;
} else {
if ((theta > -90) & (theta < -45)) {
cout<<"4"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02)) -( pi/2);
cout<<theta2<<"theta2 in radians in 4nd cond"<<endl;
} else { cout << " u didnt handle this condition "<<endl; }
}
}
}
theta2 = 180*theta2/pi;
cout <<"angle theta2 of secnod image in degrees = " <<theta2 <<endl;
cout <<"a b4 while loop = " <<a<<endl;
Results :
--------
widthis159heght is 189
60980 Non Zero Pixels in TEST
done first rotation
Angle of first image 0
60980 moo
1.93244e+009 m11
3.70591e+009 m02
2.11377e+009 m21
The ANGLE theta in radians = 1.12166
The ANGLE theta in degree = 64.2666
3
1.99214theta2 in radians in 3rd cond
angle theta2 of secnod image in degrees = 114.141
a b4 while loop = 0
!我从这里得到了这些方程1
以下是我看到的问题:
cvMoments( tempDB, &moments, 1 );
u11=cvGetCentralMoment( &moments, 1,1 );
u20=cvGetCentralMoment( &moments, 2,0 );
u02=cvGetCentralMoment( &moments, 0,2 );
cout<<moments.m00<<"moo"<<endl;
cout<<moments.m11<<"m11"<<endl;
cout<<moments.m02<<"m02"<<endl;
cout<<moments.m20<<"m21"<<endl;
/////////////////////////////////////// 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 <=45)) /*single & is binary (each bit individually) instead of the whole thing*/ {
//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 > -45) && (theta < 0)) /*same issue here*/ {
cout<<"2"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02));
cout<<theta2<<"theta2 in radians in 2nd cond"<<endl;
}
else{
if ((theta > 45) && (theta < 90)) /*the brace placement sucks, but use && instead of &*/{
cout<<"3"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02)) +( pi/2);
cout<<theta2<<"theta2 in radians in 3nd cond"<<endl;
} else {
if ((theta > -90) && (theta < -45)) {
cout<<"4"<<endl;
theta2 = 0.5*atan(2*u11/(u20-u02)) -( pi/2);
cout<<theta2<<"theta2 in radians in 4nd cond"<<endl;
} else { cout << " u didnt handle this condition "<<endl; }
}
}
}
theta2 = 180*theta2/pi;
cout <<"angle theta2 of secnod image in degrees = " <<theta2 <<endl;
cout <<"a b4 while loop = " <<a<<endl;
您正在使用&而不是&&唯一可能为假的情况是恰好是的二进制对边(不可能)。第一个if总是为真