Max Fuller
Max Fuller

Reputation: 53

OpenCV (C++) - Calculating 2D co-ordinates of an image from known 3D object and camera positions

So I already know the 3D camera position and the position and size of an object in the world frame, as well as the camera matrix and distortion coefficients from a previous camera calibration.

What I need to work out is the 2D image coordinates of the object. Let's just say the object is a sphere with world position objPos and radius objRad, so the image I want to find the coordinates for will be a circle of image position imgPos and radius imgRad.

How would I go about doing this?

Cheers

Upvotes: 0

Views: 734

Answers (1)

Adrian Schneider
Adrian Schneider

Reputation: 1507

In OpenCV exists a function to project 3D coordinates on a (camera) image - projectPoints In my opinion you have all you need for calling this function. The arguments are:

  1. 3D coordinates you want to project
  2. Rotation of your camera - rvec
  3. Position of your camera - tvec
  4. Camera matrix - from the calibration you have
  5. Camera distortion coefficients - from the calibration you have
  6. Resulting 2D image coordinates

If you have your extrinsic camera parameters in form of 4x4 matrix, you have to extract rvec and tvec from it (see here).

To come to your example case: I would generate the 3D coordinates of such a sphere with the corresponding radius. In a next step, I would project these 3D coordinate with above method.

Upvotes: 1

Related Questions