# Revision history [back]

### Translation from SolvePnP seems wrong

I am currently working on an Android AR app. I try to track an Aruco Marker to set the Cameraposition in a volume rendering process on a server.

To get the translation- and rotationvectors I am using solvePnP.

    // set the obj 3D points
double halfSize = sizeMeters / 2.0;
List<Point3> objPoints = new ArrayList<Point3>();

MatOfPoint3f objPointsMat = new MatOfPoint3f();
objPointsMat.fromList(objPoints);
MatOfPoint2f tempPoints= new MatOfPoint2f();
tempPoints.fromList(this.points);
Calib3d.solvePnP(objPointsMat, tempPoints, camMatrix, distCoeffs, Rvec, Tvec,false,Calib3d.CV_ITERATIVE);


I then try to generate the view matrix from both vectors.

            Matrix rotMat;
{
Mat rVec = data.getRVec();
Mat rMat = new Mat( 3, 3, CvType.CV_64F );
Calib3d.Rodrigues( rVec, rMat );
rotMat = new Matrix( rMat );
}

// Generate translation vector from tVec
Matrix tVec = new Matrix( data.getTVec() );

Matrix viewMat;
{
Matrix compMat = new Matrix( 4, 4, new double[]{
rotMat.get( 0, 0 ), rotMat.get( 0, 1 ), rotMat.get( 0, 2 ), tVec.get( 0, 0 ),
rotMat.get( 1, 0 ), rotMat.get( 1, 1 ), rotMat.get( 1, 2 ), tVec.get( 1, 0 ),
rotMat.get( 2, 0 ), rotMat.get( 2, 1 ), rotMat.get( 2, 2 ), -tVec.get( 2, 0 ),
0.0, 0.0, 0.0, 1.0
}
viewMat =  Matrix.transpose(compMat);


But I encountered the issue, that the object that gets rendered is not displayed correctly. It seemed, that the translation vector is not correct since the object won't stay at the marker position.

I then tried to render the object without the rotation vector and saw, that the translation vector is really a bit off. Furthermore I saw, that the error gets bigger when the distance to the marker is increased.

Did anybody encounter simiilar problems and knows where I fail? I am happy for any help.

Thank you in Advance. Best Regards Schotti

### Translation from SolvePnP seems wrong

I am currently working on an Android AR app. I try to track an Aruco Marker to set the Cameraposition in a volume rendering process on a server.

To get the translation- and rotationvectors I am using solvePnP.

    // set the obj 3D points
double halfSize = sizeMeters / 2.0;
List<Point3> objPoints = new ArrayList<Point3>();

MatOfPoint3f objPointsMat = new MatOfPoint3f();
objPointsMat.fromList(objPoints);
MatOfPoint2f tempPoints= new MatOfPoint2f();
tempPoints.fromList(this.points);
Calib3d.solvePnP(objPointsMat, tempPoints, camMatrix, distCoeffs, Rvec, Tvec,false,Calib3d.CV_ITERATIVE);


I then try to generate the view matrix from both vectors.

            Matrix rotMat;
{
Mat rVec = data.getRVec();
Mat rMat = new Mat( 3, 3, CvType.CV_64F );
Calib3d.Rodrigues( rVec, rMat );
rotMat = new Matrix( rMat );
}

// Generate translation vector from tVec
Matrix tVec = new Matrix( data.getTVec() );

Matrix viewMat;
{
Matrix compMat = new Matrix( 4, 4, new double[]{
rotMat.get( 0, 0 ), rotMat.get( 0, 1 ), rotMat.get( 0, 2 ), tVec.get( 0, 0 ),
rotMat.get( 1, 0 ), rotMat.get( 1, 1 ), rotMat.get( 1, 2 ), tVec.get( 1, 0 ),
rotMat.get( 2, 0 ), rotMat.get( 2, 1 ), rotMat.get( 2, 2 ), -tVec.get( 2, 0 ),
0.0, 0.0, 0.0, 1.0
}
viewMat =  Matrix.transpose(compMat);


But I encountered the issue, that the object that gets rendered is not displayed correctly. It seemed, that the translation vector is not correct since the object won't stay at the marker position.

I then tried to render the object without the rotation vector and saw, that the translation vector is really a bit off. Furthermore I saw, that the error gets bigger when the distance to the marker is increased.

Did anybody encounter simiilar problems and knows where I fail? I am happy for any help.

Thank you in Advance. Best Regards Schotti

### Translation from SolvePnP seems wrong

I am currently working on an Android AR app. I try to track an Aruco Marker to set the Cameraposition in a volume rendering process on a server.

To get the translation- and rotationvectors I am using solvePnP.

    // set the obj 3D points
double halfSize = sizeMeters / 2.0;
List<Point3> objPoints = new ArrayList<Point3>();

MatOfPoint3f objPointsMat = new MatOfPoint3f();
objPointsMat.fromList(objPoints);
MatOfPoint2f tempPoints= new MatOfPoint2f();
tempPoints.fromList(this.points);
Calib3d.solvePnP(objPointsMat, tempPoints, camMatrix, distCoeffs, Rvec, Tvec,false,Calib3d.CV_ITERATIVE);


I then try to generate the view matrix from both vectors.

            Matrix rotMat;
{
Mat rVec = data.getRVec();
Mat rMat = new Mat( 3, 3, CvType.CV_64F );
Calib3d.Rodrigues( rVec, rMat );
rotMat = new Matrix( rMat );
}

// Generate translation vector from tVec
Matrix tVec = new Matrix( data.getTVec() );

Matrix viewMat;
{
Matrix compMat = new Matrix( 4, 4, new double[]{
rotMat.get( 0, 0 ), rotMat.get( 0, 1 ), rotMat.get( 0, 2 ), tVec.get( 0, 0 ),
rotMat.get( 1, 0 ), rotMat.get( 1, 1 ), rotMat.get( 1, 2 ), tVec.get( 1, 0 ),
rotMat.get( -rotMat.get( 2, 0 ), rotMat.get( -rotMat.get( 2, 1 ), rotMat.get( -rotMat.get( 2, 2 ), -tVec.get( 2, 0 ),
0.0, 0.0, 0.0, 1.0
}
viewMat =  Matrix.transpose(compMat);


But I encountered the issue, that the object that gets rendered is not displayed correctly. It seemed, that the translation vector is not correct since the object won't stay at the marker position.

I then tried to render the object without the rotation vector and saw, that the translation vector is really a bit off. Furthermore I saw, that the error gets bigger when the distance to the marker is increased.

Did anybody encounter simiilar problems and knows where I fail? I am happy for any help.

Thank you in Advance. Best Regards Schotti