Nodes/comfyui_cv/cv2.findHomography
ComfyUI Node

cv2.findHomography

Raw wrapper of cv2.findHomography(srcPoints, dstPoints, method?, ransacReprojThreshold?, mask?, maxIters?, confidence?). Parameters marked '?' are optional; blank means OpenCV default. See the OpenCV documentation for details.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
cv2.findHomography
  • srcPoints
  • dstPoints
  • mask
  • H
  • mask
methodRANSAC
ransacReprojThreshold3.0000
maxIters2000
confidence0.9950
Categoryimage/CV/low-level/cv2 F

Inputs (7)

NameTypeDefaultDescription
srcPointsNPARRAYCoordinates of the points in the original plane, a matrix of the type CV_32FC2 or vector\ . A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
dstPointsNPARRAYCoordinates of the points in the target plane, a matrix of the type CV_32FC2 or a vector\ . A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
methodoptCOMBORANSACMethod used to compute a homography matrix. The following methods are possible: - **0** - a regular method using all the points, i.e., the least squares method - - RANSAC-based robust method - - Least-Median robust method - - PROSAC-based robust method
ransacReprojThresholdoptFLOAT3.0000-1e+38–1e+38Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC and RHO methods only). That is, if $$\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} \cdot \texttt{srcPoints} _i) \|_2 > \texttt{ransacReprojThreshold}$$ then the point $i$ is considered as an outlier. If srcPoints and dstPoints are measured in pixels, it usually makes sense to set this parameter somewhere in the range of 1 to 10. Preset to the OpenCV default (3.0).
maskoptNPARRAY,IMAGE,MASKOptional output mask set by a robust method ( RANSAC or LMeDS ). Note that the input mask values are ignored. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
maxItersoptINT2000-2147483648–2147483647The maximum number of RANSAC iterations. Preset to the OpenCV default (2000).
confidenceoptFLOAT0.9950-1e+38–1e+38Confidence level, between 0 and 1. The function finds and returns the perspective transformation $H$ between the source and the destination planes: $$s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}$$ so that the back-projection error $$\sum _i \left ( x'i- \frac{h{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2+ \left ( y'i- \frac{h{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2$$ is minimized. If the parameter method is set to the default value 0, the function uses all the point pairs to compute an initial homography estimate with a simple least-squares scheme. However, if not all of the point pairs ( $srcPoints_i$, $dstPoints_i$ ) fit the rigid perspective transformation (that is, there are some outliers), this initial estimate will be poor. In this case, you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different random subsets of the corresponding point pairs (of four pairs each, collinear pairs are discarded), estimate the homography matrix using this subset and a simple least-squares algorithm, and then compute the quality/goodness of the computed homography (which is the number of inliers for RANSAC or the least median re-projection error for LMeDS). The best subset is then used to produce the initial estimate of the homography matrix and the mask of inliers/outliers. Regardless of the method, robust or not, the computed homography matrix is refined further (using inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the re-projection error even more. The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to distinguish inliers from outliers. The method LMeDS does not need any threshold but it works correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the noise is rather small, use the default method (method=0). The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is determined up to a scale. If $h_{33}$ is non-zero, the matrix is normalized so that $h_{33}=1$. Preset to the OpenCV default (0.995).

Outputs (2)

NameTypeDescription
HNPARRAY
maskNPARRAY