DriveWorks SDK Reference
5.20.37 Release
For Test and Development only

Pose estimation

The tutorial shows the general structure of a program that uses the PnP pose estimator to determine the camera pose.

Initialize the pose estimator

We select a conservative number of ransac and non-linear optimizer iterations (10 and 10). contextHandle is assumed to be previously initialized dwContextHandle_t.

dwPnP_initialize(&pnp, 10, 10, contextHandle);
DW_API_PUBLIC dwStatus dwPnP_initialize(dwPnPHandle_t *obj, size_t ransacIterations, size_t optimizerIterations, dwContextHandle_t ctx)
Initializes a PnP solver.

Obtain matches

dwVector3f worldPoints[BUFFER_SIZE];
dwVector2f imagePoints[BUFFER_SIZE];
size_t pointCount;
// The application must obtain the matches and fill the above three variables
Defines a three-element floating-point vector.
Definition: MatrixTypes.h:76
Defines a two-element single-precision floating-point vector.
Definition: MatrixTypes.h:48

Undistort feature points

cameraModel is assumed to be previously initialized dwCameraModelHandle_t

dwVector2f rays[BUFFER_SIZE];
for(size_t i = 0; i < pointCount; ++i)
{
const auto& point = imagePoints[i];
auto& ray = rays[i];
dwCameraModel_pixel2Ray(&ray.x, &ray.y, &ray.z, point.x, point.y, cameraModel);
}
DW_API_PUBLIC dwStatus dwCameraModel_pixel2Ray(float32_t *x, float32_t *y, float32_t *z, float32_t u, float32_t v, dwConstCameraModelHandle_t obj)
Back-projects a 2D point in pixel coordinates to a 3D optical ray direction.

Estimate pose

dwTransformation3f worldToCamera;
dwPnP_solve(&worldToCamera, pointCount, rays, worldPoints, pnp);
DW_API_PUBLIC dwStatus dwPnP_solve(dwTransformation3f *worldToCamera, size_t matchCount, const dwVector3f *rays, const dwVector3f *worldPoints, dwPnPHandle_t obj)
Estimates the worldToCamera pose based on optical ray to 3D world point correspondences.
Specifies a 3D rigid transformation.
Definition: MatrixTypes.h:182

Finally, free previously allocated memory.

DW_API_PUBLIC dwStatus dwPnP_release(dwPnPHandle_t obj)
Releases the PnP solver.