Ask Your Question

Revision history [back]

How to create CATransform3D from homography matrix?

My app has a tilted camera setup that is looking at a reference sheet with a known image in it. I've properly created a homography that perfectly captures the relationship between the source (flat) image and the reference camera view.

What I want to do next is to take the homography matrix and apply it to my live camera view so that the live view is warped to simulate a straight-on, non-tilted setup.

In other words, I want to take the homography matrix and create an Apple iOS CATransform3D from it to apply to the view's CALayer transform property. I can find no reference to anyone who has successfully done this, although there are a few posts guessing at it.

One option is to build up the CATransform3D from scratch by applying horizontal and vertical transforms, rotation, and perspective tilt and skew. (.M34) But, I don't know how to extract these from the homography and the opencv matrix functions are way over my head to ever figure it out.

Using the homography matrix, I could literally apply it to one frame at a time to the input of the camera, but it would likely be slower than simply changing the CALayer's transform property once.

By the way, the camera does not move after the homography is created.