Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV CameraParams representation #2

Open
AlexeySrus opened this issue Jun 1, 2022 · 2 comments
Open

OpenCV CameraParams representation #2

AlexeySrus opened this issue Jun 1, 2022 · 2 comments

Comments

@AlexeySrus
Copy link

AlexeySrus commented Jun 1, 2022

Dear developers, thanks for a great toolkit.
I faced the problem of converting matrices from frames metadata to OpenCV CameraParams representation.

I read the matrices with the following code:

def read_matrix(_metadata: dict) -> np.ndarray:
    loaded_mat = np.array(_metadata['cameraPoseARFrame']).reshape(4, 4)
    y_rows = loaded_mat[1, :].copy()
    z_rows = loaded_mat[2, :].copy()

    loaded_mat[1, :] = z_rows * -1.0
    loaded_mat[2, :] = y_rows
    return loaded_mat
v_matrix = read_matrix(frame_metadata)
proj_m = np.array(frame_metadata['projectionMatrix']).reshape((4, 4))
mvp1 = proj_m @ np.linalg.inv(v_matrix)
intrinsics = np.array(frame_metadata['intrinsics']).reshape(3, 3)

Then I convert it to a OpenCV CameraParams class:

cam = cv.detail_CameraParams()
r, _, t, _, _, _, _ = cv.decomposeProjectionMatrix(mvp1[:3])
cam.R = r
cam.t = t
cam.focal = intrinsics[0, 0]
cam.ppx = intrinsics[0, 2]
cam.ppy = intrinsics[1, 2]
cam.aspect = 1

But unfortunately, I didn't get the desired results. Could you help me with camera converting question?

--
Best Regards, Alexey Kovalenko

@ghy0324
Copy link

ghy0324 commented Jan 20, 2023

@AlexeySrus Hi! I met the same problem, have you solved it?

@cclaan
Copy link
Collaborator

cclaan commented Jan 20, 2023

Maybe you could share more code of what you are trying to do with the camera in opencv? I could add an example based on that. It seems like you are exchanging y/z rather than negating them. You might also need to ignore the image orientation exif when using imread ( cv2.IMREAD_IGNORE_ORIENTATION )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants