I have an image of white paper on the desk, with a different orientation. Something like this:
Now, I detected the white paper and obtained the coordinates of the trapezium. I now have another image, say of a keyboard like this:
Now my aim is to replace that paper by this keyboard. I discovered that getPerspectiveTransform
can be used. I referred the code given here as a starter for mine.
There, in place of output
, I fed output = imread("paper.jpg")
and in place of input
, input = imread("keyboard.jpg")
. And also had detected the corners of the white sheet earlier.
It worked well by replacing the white paper by the keyboard after transformation, but the background containing the desk, the pencil, etc were blackened out. The entire background became black and only the keyboard replacing the white paper could be seen.
So I wanted to know how to replace the portion through perspective transform, still retaining the background image.