Today I came across a small application which I made during my computer vision course. It can place and stretch (or rectify) a selected area (a convex quadrilateral) from one image into an area in the other image.  The most important concept that is used is the Homography Matrix. This is a matrix representing the projective transformation from one image into the other and can be found by OpenCV’s function cvFindHomography(). I believe given a set of point correspondences, a homography can be found using either a SVD approach or a RANSAC approach. The OpenCV documentation is not clear about this and just uses “a regular method using all the points”, for now that’s fine by me :)

So, onto the images!

A lovely cat isn't it?

Compositor source image (photo by GrandiJoos)

The computer screen

Compositor destination image

Cat in screen?

Composited image

It can be seen that the input image got stretched a lot on the bottom part. There is a preciseness parameter for which 1/preciseness determines how many times the output width (height) can be larger then the input width (height). Check out the source code for details on this. Also, try adding your own images!

Download the source code here, it has been tested on Linux only.