Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Reverse camera angle

I have the Aruco tracking working and from cobbling together stuff from various code samples, ended up with the code below, where final is the view matrix passed to the camera. The problem is that the rotation of the camera isn't exactly what I need... not sure exactly which axis is wrong, but you can see in the following video that I want the base of the model to be sitting on the marker- but instead it's not oriented quite right. Any tips to get it right would be great! I'm open to re-orienting it in blender too if that's the right solution. Just not sure exactly _how_ it's wrong right now.

Video example:

https://youtu.be/-7WDxa-e2Oo

Code:

const inverse = cv.matFromArray(4,4, cv.CV_64F, [   
                                    1.0, 1.0, 1.0, 1.0,
                                    -1.0,-1.0,-1.0,-1.0,
                                    -1.0,-1.0,-1.0,-1.0,
                                    1.0, 1.0, 1.0, 1.0
                                    ]);

cv.estimatePoseSingleMarkers(markerCorners, 0.1, cameraMatrix, distCoeffs, rvecs, tvecs);
cv.Rodrigues(rvecs, rout);

const tmat = tvecs.data64F;
const rmat = rout.data64F;

const viewMatrix = cv.matFromArray(4,4,cv.CV_64F, [ 
                                    rmat[0],rmat[1],rmat[2],tmat[0],
                                    rmat[3],rmat[4],rmat[5],tmat[1],
                                    rmat[6],rmat[7],rmat[8],tmat[2],
                                    0.0,0.0,0.0,1.0
                                    ]);

const output = cv.Mat.zeros(4,4, cv.CV_64F);
cv.multiply(inverse, viewMatrix, output);

cv.transpose(output, output);
const final = output.data64F;

Reverse camera angle

I have the Aruco tracking working and from cobbling together stuff from various code samples, ended up with the code below, where final is the view matrix passed to the camera. The problem is that the rotation of the camera isn't exactly what I need... not sure exactly which axis is wrong, but you can see in the following video that I want the base of the model to be sitting on the marker- but instead it's not oriented quite right. Any tips to get it right would be great! I'm open to re-orienting it in blender too if that's the right solution. Just not sure exactly _how_ it's wrong right now.

Video example:

https://youtu.be/-7WDxa-e2Oo

Code:

const inverse = cv.matFromArray(4,4, cv.CV_64F, [   
                                    1.0, 1.0, 1.0, 1.0,
                                    -1.0,-1.0,-1.0,-1.0,
                                    -1.0,-1.0,-1.0,-1.0,
                                    1.0, 1.0, 1.0, 1.0
                                    ]);

cv.estimatePoseSingleMarkers(markerCorners, 0.1, cameraMatrix, distCoeffs, rvecs, tvecs);
cv.Rodrigues(rvecs, rout);

const tmat = tvecs.data64F;
const rmat = rout.data64F;

const viewMatrix = cv.matFromArray(4,4,cv.CV_64F, [ 
                                    rmat[0],rmat[1],rmat[2],tmat[0],
                                    rmat[3],rmat[4],rmat[5],tmat[1],
                                    rmat[6],rmat[7],rmat[8],tmat[2],
                                    0.0,0.0,0.0,1.0
                                    ]);

const output = cv.Mat.zeros(4,4, cv.CV_64F);
cv.multiply(inverse, viewMatrix, output);

cv.transpose(output, output);
const final = output.data64F;