0

My problem is exactly the reverse of How to determine world coordinates of a camera?.

If R and t are the vector of orientation and position of the camera in the world space? How do I transform easily back to the same space like the rvec and tvec?

Community
  • 1
  • 1
tomriddle_1234
  • 3,145
  • 6
  • 41
  • 71
  • do you want to transform some real world point coordinates to local camera coordinares? have a look at computer graphics theory. afair it should be just to multiply the 3D point by the inverse of the camera matrix. – Micka Apr 19 '15 at 07:48
  • look here [Understanding 4x4 homogenous transform matrices](http://stackoverflow.com/a/28084380/2521214) just keep in mind that camera matrix is Inverse – Spektre Apr 20 '15 at 07:57
  • @Micka, because I made a mistake about what's [R|t] in the projection matrix. I calculated the R and t of the camera in the world space. So now I wish to transform them back to the camera space without coding too much. – tomriddle_1234 Apr 20 '15 at 10:27
  • in my understanding from "camera space" R is unit mat and t is zero everywhere for a camera in its own "camera space" (if points are given in camera space you can perform standard projection), but I might be wrong there... – Micka Apr 20 '15 at 11:06

1 Answers1

2

If you say you do have an R and t in world space, then this is not very accurate.

However, let us assume that R and t (a 3x3 rotation matrix and 3x1 translation vector) represent the orientation and translation which are used to transform a point Xw in world space to a point in camera space Xc (no homogeneuos coordinates) :

Xc = R*Xw + t

These are the R and t, which are part of your projection matrix P (which is applicable with homogeneous coordinates) and the result of solvePnP (see Note at the bottom):

P = K[R|t]

The t is the world origin in camera space.

The other way round, to transform a point in camera space to world space, can be easily derived since the inverse of the orthogonal matrix R is R' (R transposed):

 Xw = R'*Xc - R't

As you can see R' (3x3 matrix) and - R't (3x1 vector) are now the orientation matrix respectively translation vector to transform from camera to world space (more precise - R't is the camera origin/center in world space often referred to as C).

Note: rvec is in the form of rotation vectors, as you may know Rodrigues() is used to switch between the two representations.

gfkri
  • 2,151
  • 21
  • 23
  • My purpose is to compose the P=K[R|t] projection matrix correctly. However, as your [previous answer](http://stackoverflow.com/questions/29720370/how-to-form-a-projection-matrix-in-opencv-and-matlab-calibration-tool-box), R doesn't change no matter it is in the world space or camera space. So Xc is a 3x1 position vector, can it be the t in the P=K[R|t] ? – tomriddle_1234 Apr 29 '15 at 07:29
  • And I tested your P=K[R|-Rc] where c is the camera center coordinate in the worldspace, but this projection matrix is wrong, tested in my reconstruction algorithm. – tomriddle_1234 Apr 29 '15 at 07:31
  • 1
    No, you misunderstood this. First of all, you cannot say that a matrix `R` **is** in a certain space. It is a transformation, more precise a rotation, which helps to get from one space to another, but it is not **in** a certain space. And of course this matrix changes, depending on the spaces you want to switch. Second the projection matrix transforms any homogeneous point from world to camera space and maps it onto the image plane afterwards. To build it use the `R` and `t` from `solvePnP` (you get the matrix `R` with `Rodrigues()`). – gfkri Apr 29 '15 at 07:53
  • `Xc` and `Xw` are just arbitrary points in the respective spaces to illustrate the transformation. And don't forget the instrinsics, for your projection matrix. – gfkri Apr 29 '15 at 07:53
  • Thanks gfkri. My problem is I have partial R and t information from my calibration, and I must recover more view's R and t from the existing ones. So that directly calculated on R and t from the `solvePnP` does not make sense, I have to transform these R and t into the world space, then recover. So my question is actually is how could I transform them back? – tomriddle_1234 Apr 29 '15 at 11:51
  • Actually, let me make a practical example. I have one view, rvec and tvec from OpenCV. Now I need to know another view's rvec and tvec, and this view is at the clockwise 30 degree according to the rotation normal [x,y,z] from the current view. So how do I get the new rvec and tvec ? – tomriddle_1234 Apr 29 '15 at 13:08