I want to use Android's gyro/accelerometer/magnetometer to predict (over a very short time interval) how image points corresponding to a fixed object will change (without trying to scan for them in the image). In particular, suppose we have an object of known size with model points $v_1, \dots, v_N$. In this question, all vectors are assumed to be in homogenous form.
Here is what I am trying:
Detect the object. Let the pixel coordinates of the model points be denoted by $u_1, \dots, u_N$. Given the calibration matrix $K$ and negligible lens distortion, solve the PnP problem to get rotation $R_0$ and translation $t_0$ from the coordinates in which the vectors $v_1, \dots, v_N$ are defined into camera-centric coordinates, shown in black in the image above. In particular, the solution to the PnP problem solves the following equation. $$ u_i = K \begin{bmatrix} R_0 & t_0 \\ 0^\top & 1\end{bmatrix} v_i. $$
Simultaneously query the Android rotation sensor for a rotation matrix.
This is the relative orientation from Earth coordinates to the device coordinates (colored frame in the picture above). The direction of the this transformation is discussed informally in the Android developer site:
The rotation vector represents the orientation of the device as a combination of an angle and an axis, in which the device has rotated through an angle $\theta$ around an axis ($x$,$ y$, or $z)$.
Let $R_1$ denote this rotation matrix.
Rotate the phone a small amount and query the rotation sensor again for $R_2$.
Render the predicted location to the pixel coordinates. For this, lets assume the sensors and the camera are collocated, so that the transformation from camera coordinates to device coordinates is a pure rotation: $$ D= \begin{bmatrix} 0 & -1 & 0 & 0\\ -1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} $$ This matrix maps the black frame to the colorful frame in the picture. Note that the $+z$ axis of the camera frame (black in the picture) is meant to point out of the back of the phone, so that it constitutes a right-handed coordinate frame.
The transformation from the body coordinates of the object $v_1, \dots, v_N$ to the image coordinates in the perturbed camera frame $u_1', \dots, u_N'$ are given by $$ u_i' =KD\begin{bmatrix}R_2 R_1^\top & 0 \\ 0^\top & 1 \end{bmatrix} D \begin{bmatrix} R_0 & t_0 \\ 0^\top & 1 \end{bmatrix} v_i, $$ where we used the fact that $D=D^{-1}.$
Right now, I am stuck tying to verify that this equation actually works. Here is a simple experiment (that I have tried in Python). Let $v = (0, 0, 1)^\top,$ and suppose it is already defined in the camera coordinate frame, i.e., $R_0=I$ and $t_0=0.$ Moreover assume that $R_1= I,$ Then, I rotate the device by a small angle about the $x$ or $y$ axis (which are the same for the device and for the Earth because $R_1=I.$) This rotation constitutes $R_2$ from the equations above. When I try this in Python, this is what I observe for various counter-clockwise rotations:
test rotation of device :: expected result :: observed result
rotate device about $+x$ :: $x$ pixel coordinate increases :: opposite behavior
rotate device about $-x$ :: $x$ pixel coordinate decreases :: opposite behavior
rotate device about $+y$ :: $y$ pixel coordinate decreases :: as expected
rotate device about $-y$ :: $y$ pixel coordinate increases :: as expected