-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Proper extrapolation with findHomography #18254
Description
- OpenCV => 4.4.0.42
- Operating System / Platform => Ubuntu 18.04
There is this simple case I plotted, where the source points of the homography is a simple square side==100 and the destination points is a square with side==10
(0,0) are the same in both planes
Inferring the homography matrix with 'findHomography' works fine here
So this is the plot with some other points inferred from 'perspectiveTransform' function:

This is straightforward correct, as the red points is kinda notable solutions
Point is, this system shouldn't be easily extrapolated given 3 points, or am I assuming constraints?
Removing the source point in [100,100] gives this answers:

How can it be so different from the obvious solution from the first case?
It is well documented that if the matchs aren't rigid, its estimation is poor, is this case not rigid?
It would be great if this was properly extrapolated for a rhombus shape
Passing a non-collinear 4th point anywhere gives the clean solution as well

code(python):
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
anchors = np.array([[0,0],[100,0],[0,100],[100,100]] ,dtype=np.float32)
values = np.array([[0,0],[10,0],[0,10],[10,10]] ,dtype=np.float32)
grid_points = np.array( [[[100,50] , [50,50] , [50,0] , [25,25]]] ,dtype=np.float32)
A,mask = cv.findHomography( anchors , values )
grid_values = cv.perspectiveTransform( grid_points , A )
#PyPlot'ing
plt.figure(figsize=(10,10))
plt.plot( anchors[:,0] , anchors[:,1] , '.' , ms=20 )
for i in range(0,len(anchors)):
plt.text(anchors[i,0]-1,anchors[i,1]+5, str(values[i]) )
plt.plot( grid_points[0,:,0] , grid_points[0,:,1] , '.' , ms=5 )
for i in range(0,len(grid_points[0])):
plt.text( grid_points[0,i,0]-1 , grid_points[0,i,1]-5 , str('{:.2f},{:.2f}'.format(grid_values[0,i,0],grid_values[0,i,1])) , color='red')
plt.show()