getprespectivetransform or alternatives which one is better [closed]
I have identified a rectangular area in my image space ( programmetically I have fuor points in a vector representing vertices of a rectangle or quadrilateral ) in live camera feed. The shape is unknown in advance but it is known that it is a polygon with 4 vertices. I would like to display an image within that area. Here is my code.
vector<Point2f> knownLiveFeedPoints; // this vector contains four Point2f Coordinates
Mat repImage = imread("replace1.jpg");
vector<Point2f> imagePoints = { Point2f(0, 0), Point2f(repImage.cols, 0),
Point2f(repImage.cols, repImage.rows), Point2f(0, repImage.rows), };
Mat transmix = getPerspectiveTransform(imagePoints, knownLiveFeedPoints);
warpPerspective(repImage, cameraFeed, transmix, cameraFeed.size(), cv::INTER_LINEAR, cv::BORDER_TRANSPARENT);
This is working fine. Here I would like to know what is being done by getPrespectiveTransform ( would really appreciate a sample matrix calculation ) and wrapPrespective ? I went through openCV documentation many times but got lost in many alternatives and generic explanation. Can I achieve exactly same functionality using findHomography() ? what would be the difference ? Thanks in advance.
findHomography is for 3D objects, while warpPerspective is for 2D planar objects. The first one is a more complex version of the second one (in big lines). So I would not suggest you to use the findHomography for a quadrilateral object, except if it is an object that may deform (like a silk, it may get curved or something like that...)
@thdrksdfthmn thanks for the explanation. Can you please explain how transmix (in my code) is computed in matrix format? or provide some URL which explains the calculation in simple form with an example.
Have you google it?
I need exactly what happens at matrix level, so far couldn't find it over google.
OK, you don't get it from the wikipedia... The idea is that you give the 4 points in the order that you fixed (so, after the projection, you'll get the frontal object); Based on their places, and the expected position, it will compute the angle of rotation (θ), the factor of shearing (k), and the reflection (if there is one). If you want even deeper info, then you shall go in the code, to see exactly how it is done...