algorithm - Not getting the correct orientation of the user with respect to Kinect -
i using microsoft kinect in project. 1 of task have accomplish find orientation of user w.r.t kinect sensor (when user turns, orientation changes) this, trying find angle line joining shoulders makes x axis of kinect.
i have come following code, gives me small angle values, when turn 40 degrees.
double vector_x=skel.skeletonpositions[nui_skeleton_position_shoulder_left].x-skel.skeletonpositions[nui_skeleton_position_shoulder_right].x; double vector_y=skel.skeletonpositions[nui_skeleton_position_shoulder_left].y-skel.skeletonpositions[nui_skeleton_position_shoulder_right].y; double vector_z=skel.skeletonpositions[nui_skeleton_position_shoulder_left].z-skel.skeletonpositions[nui_skeleton_position_shoulder_right].z; double len1=sqrtf(vector_x * vector_x + vector_y * vector_y + vector_z * vector_z); double vector_x1=1.0; double vector_y1=0.0; double vector_z1=0.0; double len2=sqrtf(vector_x1 * vector_x1 + vector_y1 * vector_y1 + vector_z1 * vector_z1); double dot_product = vector_x * vector_x1 + vector_y * vector_y1 + vector_z * vector_z1; double angle = dot_product / (len1 * len2); coor_left=convert(vector_x)+"\t"+convert(vector_y)+"\t"+convert(vector_z)+"\n"; outputdebugstringa(convert(acos(angle)).c_str());
when added conversion of radians degrees,
double angle1=angle*180.0/3.14;
i values form -33 -57(when facing kinect) , -33 again.
but in reality, should negative, 0 , positive on other side. going wrong?
i solved myself. realised finding angle between incorrect vectors.
all needed take projection of left , right shoulders on x-z plane , reduce problem finding angle between 2 vectors in plane.
here did:
double calcangle(double p1x,double p1y, double p2x,double p2y, double p3x,double p3y, double p4x,double p4y) { // // calculate angle between line p1 p2 // , line p3 p4 // double x1 = p1x - p2x; double y1 = p1y - p2y; double x2 = p3x - p4x; double y2 = p3y - p4y; // double angle1 , angle2 , angle; // if (x1 != 0.0f) angle1 = atan(y1/x1); else angle1 = 3.14159 / 2.0; // 90 degrees // if (x2 != 0.0f) angle2 = atan(y2/x2); else angle2 = 3.14159 / 2.0; // 90 degrees // angle = fabs(angle2-angle1); angle = angle * 180.0 / 3.14159; // convert degrees ??? // return angle; } double myangle=calcangle(skel.skeletonpositions[nui_skeleton_position_shoulder_left].x,skel.skeletonpositions[nui_skeleton_position_shoulder_left].z, skel.skeletonpositions[nui_skeleton_position_shoulder_right].x,skel.skeletonpositions[nui_skeleton_position_shoulder_right].z, 0,0,1,0); outputdebugstringa(convert(myangle).c_str()); outputdebugstringa("\n");
Comments
Post a Comment