Nodes/ComfyUI CV/cv2.findFundamentalMat (2/2)
ComfyUI Node

cv2.findFundamentalMat (2/2)

Cv2.findFundamentalMat (2/2)

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
cv2.findFundamentalMat (2/2)
  • points1
  • points2
  • mask
  • F
  • mask
◄methodFM_RANSAC►
◄ransacReprojThreshold3.0000►
◄confidence0.9900►

Of the two cv2.findFundamentalMat nodes in this pack, this is the one to default to. Same function, same outputs - but this overload only has points1 and points2 as required, and the wrapper presets OpenCV's documented defaults for everything else: FM_RANSAC, a 3.0 pixel reprojection threshold, 0.99 confidence. Which is to say, it works if you just wire it up.

The other overload, (1/2), declares the method and all the RANSAC parameters as required, so their widget defaults sit at 0 and you have to fill in values cv2 would have chosen for you. Use that one only when you specifically want FM_7POINT or FM_8POINT, or need to pin the iteration count.

What F is for

The fundamental matrix encodes the epipolar geometry between two views of a scene, in image coordinates only - no camera intrinsics required. If you know what a point in image 1 corresponds to, F tells you the line in image 2 it must lie on. That's the whole basis of epipolar verification (do my matches make geometric sense?), sparse stereo, and uncalibrated rectification.

It's also the honest tool when you have no calibration: an essential matrix needs intrinsics, F doesn't.

Inputs

points1 and points2 are the matched correspondences from a single matching pass, floating point, equal length, at least 8 points. Both are NPARRAY-only data sockets.

method - the dropdown offers FM_RANSAC (default, and what you want for real feature matches), FM_LMEDS (least median; needs more than half your points to be inliers), FM_8POINT (no robustness at all, only for clean synthetic correspondences) and FM_7POINT (exactly 7 points, non-robust, and it can return multiple solutions - see below).

ransacReprojThreshold is presets to 3.0, which is the value OpenCV documents: the maximum distance from a point to its epipolar line, in pixels, before it counts as an outlier. confidence presets to 0.99, the probability the estimate is correct. There's no maxIters widget on this overload - that's the trade you accept for the convenience.

And the optional mask input. It's the C++ output-buffer parameter; passing it something achieves nothing. The mask you want is an output.

Outputs

F, the 3×3 fundamental matrix, and mask, the Nx1 uint8 inlier mask.

Read the mask. It's the difference between "geometry" and "a plausible-looking matrix fitted to garbage" - and F is especially good at looking plausible. A match set with 12 inliers out of 300 will still produce a well-formed F. The inlier count is the number that tells you whether to keep going.

Then the FM_7POINT trap, which applies here too: that algorithm can return up to three candidate matrices, and cv2 stacks them into one 9×3 array. Feed that to cv2_computeCorrespondEpilines or cv2_stereoRectifyUncalibrated and you get silent nonsense. The curated CV Find Fundamental Matrix node takes the first 3×3 and reports a found flag, which is a good reason to use it instead of raw wrappers for anything you'll actually rely on.

Where the outputs go: CV Draw Epipolar Lines for the visual check (lines from image 1 should pass through the matched points in image 2 - if they don't, nothing downstream is worth running), cv2_stereoRectifyUncalibrated to get the two rectifying homographies, then a matcher like CV Stereo Disparity (SGBM) on the rectified pair. The pack's exercise_epipolar_geometry.json and exercise_stereo_rectification.json are the working references.

The degeneracy nobody warns you about

Correspondences from a single plane - a wall, a poster, a chessboard on a table - are a degenerate configuration for F. It will still return a matrix, and it will still be wrong. Use views of a scene with depth from a camera that translated, not just rotated.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Or Manager → "ComfyUI CV" → install → restart. Python ≥ 3.12, V3-API ComfyUI.

Common issues

cv2 raises, or F comes back as garbage. Fewer than 8 points on the robust methods. Count first - Inspect CV Data gives you shapes and dtypes.

F is fine but the epipolar lines look wrong. Almost always the point order convention: computeCorrespondEpilines needs to know which image the points came from, and getting it backwards mirrors the whole result. The pack's CV Draw Epipolar Lines node has that as a dropdown, exactly because it's easy to flip.

Unstable results run to run. RANSAC draws random subsets; a low inlier ratio means different runs land on different subsets. Raise the threshold a touch, or improve the matches - and if you want repeatability above all, the pack's CV Random Seed node reseeds cv2's RNG.

Categoryimage/CV/low-level/cv2 F

Inputs (6)

NameTypeDefaultDescription
points1NPARRAYArray of N points from the first image. The point coordinates should be floating-point (single or double precision). A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
points2NPARRAYArray of the second image points of the same size and format as points1 . A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
methodoptCOMBOFM_RANSACMethod for computing a fundamental matrix. - for a 7-point algorithm. $N = 7$ - for an 8-point algorithm. $N \ge 8$ - for the RANSAC algorithm. $N \ge 8$ - for the LMedS algorithm. $N \ge 8$
ransacReprojThresholdoptFLOAT3.0000-1e+38–1e+38Parameter used only for RANSAC. It is the maximum distance from a point to an epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution, and the image noise. Preset to the OpenCV default (3.0).
confidenceoptFLOAT0.9900-1e+38–1e+38Parameter used for the RANSAC and LMedS methods only. It specifies a desirable level of confidence (probability) that the estimated matrix is correct. Preset to the OpenCV default (0.99).
maskoptNPARRAY,IMAGE,MASK - - - 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.

Outputs (2)

NameTypeDescription
FNPARRAY—
maskNPARRAY—