Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

3D rotation matrix between 2 axis

$
0
0
I have 2 known 3d points which are the origin of 2 axis plot in the space and I need to compute the 3D rotation matrix between them. I didn't really get what the difference Euler angles and the other type of angles? Any help please? **EDITED**: ![image description](/upfiles/14370470003199331.png) I have Oc1 and Oc2 known points in the space and I know that using R1&T1 I can get to Oc1 and using R2&T2 I can get to Oc2 but I need to compute the 3D rotation matrix between Oc1 and Oc2. Is there any openCV method that computes such rotation? **EDITED** Here my code for a sample to test `c1Mc2 = (oMc1)^-1 oMc2`: vector listOfPointsOnTable; cout << "******** DATA *******" << endl; listOfPointsOnTable.push_back(Point3f(0,0,0)); listOfPointsOnTable.push_back(Point3f(100,0,0)); listOfPointsOnTable.push_back(Point3f(100,100,0)); listOfPointsOnTable.push_back(Point3f(0,100,0)); cout << endl << "Scene points :" << endl; for (int i = 0; i < listOfPointsOnTable.size(); i++) { cout << listOfPointsOnTable[i] << endl; } //Define the optical center of each camera Point3f centreOfC1 = Point3f(23,0,50); Point3f centreOfC2 = Point3f(0,42,20); cout << endl << "Center Of C1: " << centreOfC1 << " , Center of C2 : " << centreOfC2 << endl; //Define the translation and rotation between main axis and the camera 1 axis Mat translationOfC1 = (Mat_(3, 1) << (0-centreOfC1.x), (0-centreOfC1.y), (0-centreOfC1.z)); float rotxC1 = 0, rotyC1 = 0, rotzC1 = -45; int focaleC1 = 2; Mat rotationOfC1 = rotation3D(rotxC1, rotyC1,rotzC1); cout << endl << "Translation from default axis to C1: " << translationOfC1 << endl; cout << "Rotation from default axis to C1: " << rotationOfC1 << endl; Mat transformationToC1 = buildTransformationMatrix(rotationOfC1, translationOfC1); cout << "Transformation from default axis to C1: " << transformationToC1 << endl << endl; //Define the translation and rotation between main axis and the camera 2 axis Mat translationOfC2 = (Mat_(3, 1) << (0-centreOfC2.x), (0-centreOfC2.y), (0-centreOfC2.z)); float rotxC2 = 0, rotyC2 = 0, rotzC2 = -90; int focaleC2 = 2; Mat rotationOfC2 = rotation3D(rotxC2, rotyC2,rotzC2); cout << endl << "Translation from default axis to C2: " << translationOfC2 << endl; cout << "Rotation from default axis to C2: " << rotationOfC2 << endl; Mat transformationToC2 = buildTransformationMatrix(rotationOfC2, translationOfC2); cout << "Transformation from default axis to C2: " << transformationToC2 << endl << endl; Mat centreOfC2InMat = (Mat_(3, 1) << centreOfC2.x, centreOfC2.y, centreOfC2.z); Mat centreOfC2InCamera1 = rotationOfC1 * centreOfC2InMat + translationOfC1; Mat translationBetweenC1AndC2 = -centreOfC2InCamera1; cout << endl << "****Translation from C2 to C1" << endl; cout << translationBetweenC1AndC2 << endl; Mat centreOfC1InMat = (Mat_(3, 1) << centreOfC1.x, centreOfC1.y, centreOfC1.z); Mat centreOfC1InCamera2 = rotationOfC2 * centreOfC1InMat + translationOfC2; Mat translationBetweenC2AndC1 = -centreOfC1InCamera2; cout << "****Translation from C1 to C2" << endl; cout << translationBetweenC2AndC1 << endl; cout << "Tran1-1 * Trans2 = " << transformationToC1.inv() * transformationToC2 << endl; cout << "Tran2-1 * Trans1 = " << transformationToC2.inv() * transformationToC1 << endl; Mat rotation3D(int alpha, int beta, int gamma) { // Rotation matrices around the X, Y, and Z axis double alphaInRadian = alpha * M_PI / 180.0; double betaInRadian = beta * M_PI / 180.0; double gammaInRadian = gamma * M_PI / 180.0; Mat RX = (Mat_(3, 3) << 1, 0, 0, 0, cosf(alphaInRadian), sinf(alphaInRadian), 0, -sinf(alphaInRadian), cosf(alphaInRadian)); Mat RY = (Mat_(3, 3) << cosf(betaInRadian), 0, sinf(betaInRadian), 0, 1, 0, -sinf(betaInRadian), 0, cosf(betaInRadian)); Mat RZ = (Mat_(3, 3) << cosf(gammaInRadian), sinf(gammaInRadian), 0, -sinf(gammaInRadian),cosf(gammaInRadian), 0, 0, 0, 1); // Composed rotation matrix with (RX, RY, RZ) Mat R = RX * RY * RZ; return R; } Mat buildTransformationMatrix(Mat rotation, Mat translation) { Mat transformation = (Mat_(4, 4) << rotation.at(0,0), rotation.at(0,1), rotation.at(0,2), translation.at(0,0), rotation.at(1,0), rotation.at(1,1), rotation.at(1,2), translation.at(1,0), rotation.at(2,0), rotation.at(2,1), rotation.at(2,2), translation.at(2,0), 0, 0, 0, 1); return transformation; } here is the output: //Origin of 3 axis O(0,0,0), OC1 (23, 0, 50), OC2 (0, 42, 20) Translation from default axis to OC1: [-23; 0; -50] Rotation from default axis to OC1: [0.7071067690849304, -0.7071067690849304, 0; 0.7071067690849304, 0.7071067690849304, 0; 0, 0, 1] Trans1 = Transformation from default axis to OC1: [0.7071067690849304, -0.7071067690849304, 0, -23; 0.7071067690849304, 0.7071067690849304, 0, 0; 0, 0, 1, -50; 0, 0, 0, 1] Translation from default axis to OC2: [0; -42; -20] Rotation from default axis to OC2: [-4.371138828673793e-08, -1, 0; 1, -4.371138828673793e-08, 0; 0, 0, 1] Trans2 = Transformation from default axis to OC2: [-4.371138828673793e-08, -1, 0, 0; 1, -4.371138828673793e-08, 0, -42; 0, 0, 1, -20; 0, 0, 0, 1] (Trans1)-1 * (Trans2) = [0.7071067623795453, -0.7071068241967844, 0, -13.43502907247513; 0.7071068241967844, 0.7071067623795453, 0, -45.96194156373071; 0, 0, 1, 30; 0, 0, 0, 1] (Trans2)-1 * (Trans1) = [0.7071067381763105, 0.7071067999935476, 0, 42.00000100536185; -0.7071067999935475, 0.7071067381763104, -0, 22.99999816412165; 0, 0, 1, -30; 0, 0, 0, 1] //Calculation of translation between OC1 and OC2: ****Translation from C2 to C1 [52.69848430156708; -29.69848430156708; 30] ****Translation from C1 to C2 [1.005361930594972e-06; 19; -30] As you can see above, the 4th column of `(Trans1)-1 * (Trans2)` is not equal neither to the translation from C2->C1 nor translation from C2->C1 it lets me think that `c1Mc2 = (oMc1)^-1 oMc2` does not get what I want

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>