OpenCV rotation matrix to Unreal rotation matrix

I’m using a VR headset and need to attach a virtual object to an ArUco marker. The virtual object’s rotation needs to match the marker’s.

Using OpenCV, I am able to calculate the translation vector and rotation matrix of the marker in the camera’s space. The problem is that OpenCV’s coordinate system is right-handed (+X: right, +Y: down, +Z: forward) while Unreal’s coordinate system is left-handed (+X: forward, +Y: right, +Z: up).

I was able to get the translation correct, but I’m having difficulty converting the OpenCV rotation matrix to work correctly inside Unreal. I’ve tried just switching the values of the rotation matrix based on matching the axes (setting my Unreal rotation matrix’s X values to be equal to my OpenCV rotation matrix’s Z values and so on), but that hasn’t worked. I’m also doing this in a C++ script.

Any help with my problem would be very appreciated.