![]() |
|
Matrix camera (for augmented reality app) - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab3d.PowerToys (https://forum.ab4d.com/forumdisplay.php?fid=9) +--- Thread: Matrix camera (for augmented reality app) (/showthread.php?tid=4397) |
Matrix camera (for augmented reality app) - SLH - 06-01-2023 Hi, I'm trying to put together an AR demo based on examples from Opencv+opengl. The sort of application I need to get working is https://rdmilligan.wordpress.com/2015/10/15/augmented-reality-using-opencv-opengl-and-blender/ I have the 4x4 view matrix (and also a projection matrix) but am struggling to work out how to get that information pushed to the cameras. Thanks for any help! Simon RE: Matrix camera (for augmented reality app) - abenedik - 06-05-2023 Sorry, but there is currently no support for newer VR headsets. There is support for Oculus Rift (https://github.com/ab4d/Ab3d.OculusWrap), but this is probably outdated. Also, there is no support for any Computer vision library (e.g. OpenCV). RE: Matrix camera (for augmented reality app) - SLH - 06-05-2023 Hi, Thanks for the response. I *think* I just need some help in porting over the code for setting the view/projection matrix - or similar. Opencv gives us the rotation and translation vector for the pose of the camera. In Opengl, these can just be manipulated a little to build matricies for adjusting the view/projection matrix. But I can't see how to do this in AB4D. I can however get the roll/pitch/yaw and position for the camera, but again, not sure how to get these values to work with any of the cameras available. I've sent a request to AB4D contact page about purchasing support. Maybe we move the conversation there? RE: Matrix camera (for augmented reality app) - abenedik - 06-05-2023 I see now that I have misunderstood the question: there is no need for VR support and you already have figured out how to get data from OpenCV. In case you only need to set view and projection matrices to the camera, then you should not create a TargetPositionCamera (or any other camera from Ab3d.PowerToys) and you should not create the CameraMouseController. Instead you can use the WPF's Matrix camera: Code: var matrixCamera = new MatrixCamera(viewMatrix, projectionMatrix);RE: Matrix camera (for augmented reality app) - SLH - 06-10-2023 Just an update: although I thought I had everything working I don't quite. Will post some code for review when I get the time. RE: Matrix camera (for augmented reality app) - SLH - 06-12-2023 [More attachments in following post] Here's my progress so far... The test object should be a blue box the size of the marker, with a red box indicating the centre and then a grid of spheres just to show a bunch of positions in 3D space. The translation tracking appears to be working (the red square is always in the centre of the marker). But the rotations are wrong. It looks like I need to add a rotation around one axis or flip an axis. But I have no idea where or how. Here is my code for the important bits. Hopefully someone can spot an obvious bug! View matrix code from the pose provided by openCV. cvRotation is the rodrigues function's output from the rotation. It is 3x3 matrix. cvT is the translation: Code: private SharpDX.Matrix OpenCVToWPFViewMatrix(Mat cvRotation, Mat cvT)projection matrix code, again, likely something is backwards or flipped in here: Code: private SharpDX.Matrix OpenCVTOWPFProjectionMatrix(Size imgSize)Code to convert to WPF matrix and back. Too many formats of Matrix in this project - maybe here I am getting something wrong? Code: private SharpDX.Matrix3x3 Mat3x3ToSharpDXMatrix(Mat r)RE: Matrix camera (for augmented reality app) - SLH - 06-12-2023 A couple more pictures of the result. NB. The drawn axis lines are from Opencv code. So I can see the coordinates of the marker there. As you can sort of tell, the rotation around one axis is off. The code is largely attempted ports of opengl example code. Am I getting some weird left-right handed coodinate system error? If so, how do I fix? RE: Matrix camera (for augmented reality app) - abenedik - 06-14-2023 If you have the matrices in left-coordinate system, then you should convert them to DirectX / WPF 3D right-handed coordinate system (x - right, y - up, z - towards the viewer). You should probably do that by multiplying by the following matrix: Code: // The transformation defines the new axis - defined in matrix columns in upper left 3x3 part of the matrix:I cannot test that so I cannot say if this will work. As you see from the values, this matrix preserves the x value, swaps the x and z value and negates the z value. The offset (the last row) is preserved. It may be also possible that you would need to transpose the matrix (some matrices are defined as row-first, and some as column-first). But if this would be the case, then you would probably not see anything - the scene would be too distorted. I hope that this will solve your problem. |