Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@marcoE sorry I thought that the two images were already alingned, my bad. Well, what you need is to find the transformation matrix between the two images, with the findHomography() function. In order to do that you need to find at least 4 points that correspond to each other in the two images and then apply the transformation by using the extracted transformation matrix in the warpperspective() function. Usually, people for that they use a feature keypoints extraction algorithm, like surf,sift, etc... find the matched points and then use them to extract the transformation matrix as I described above. You need these 4 points at least, so if you have them somehow from a previous process (contours, canny, whatever...) to the two images you can use them, if not then you need to extract them somehow. Looking at your two images, extracting features with a keypoints algorithm I do not think that it will work. What I see that you can do is to extract the horizontal and vertical lines and use the endpoints as the needed points for the homography and then apply the transformation as I described above.

@marcoE sorry I thought that the two images were already alingned, my bad. Well, what you need is to find the transformation matrix between the two images, with the findHomography() function. In order to do that you need to find at least 4 points that correspond to each other in the two images and then apply the transformation by using the extracted transformation matrix in the warpperspective() function. Usually, people for that they use a feature keypoints extraction algorithm, like surf,sift, etc... find the matched points and then use them to extract the transformation matrix as I described above. You need these 4 points at least, so if you have them somehow from a previous process (contours, canny, whatever...) to the two images you can use them, if not then you need to extract them somehow. Looking at your two images, extracting features with a keypoints algorithm I do not think that it will work. What I see that you can do is to extract the horizontal and vertical lines and use the endpoints as the needed points for the homography and then apply the transformation as I described above.

In order to see about what I am talking have a look in some examples here and here. if you search about warpperspective align two images opencv in the web you will find some other examples as well.