Nodes/comfyui_cv/CV Detect Line Segments (FLD)
ComfyUI Node

CV Detect Line Segments (FLD)

Fast Line Detector (cv2.ximgproc.createFastLineDetector): runs Canny, chains the edge pixels and splits each chain where it stops being straight. It is a cv2 CLASS, so the generated wrappers cannot reach it. Against the other two: cv2_HoughLinesP votes for INFINITE lines and cuts them afterwards (it fuses collinear edges and needs three thresholds); 'OpenCV Detect Line Segments (LSD)' works on the gradient field with no edge step and measures a width and an NFA per segment; FLD is the fastest of the three, has an explicit length threshold, and can MERGE collinear neighbours back together (do_merge) - the one thing LSD will not do. Set canny_aperture_size to 0 to feed your OWN edge map (cv2.Canny, Structured Edge Detection, a thresholded gradient...) instead of its internal Canny. Finding nothing is a valid result (count = 0, empty arrays), never an error.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Detect Line Segments (FLD)
  • image
  • segments
  • lengths
  • count
length_threshold10
distance_threshold1.4
canny_th150
canny_th250
canny_aperture_size3 (default)
do_mergefalse
min_length0
Categoryimage/CV/contrib

Inputs (8)

NameTypeDefaultDescription
imageNPARRAY,IMAGEImage to search (converted to grayscale internally). Feed the ORIGINAL image - unless canny_aperture_size is 0, in which case feed a BINARY edge map. 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.
length_thresholdINT103–10000Segments shorter than this many pixels are discarded by the detector itself (unlike LSD, which has no length knob and needs a post-filter). Raise it to keep only structural edges.
distance_thresholdFLOAT1.40–100A pixel farther than this from the hypothesised line is an outlier, which ends the segment. Small = many short straight pieces; large = fewer, looser segments that bend.
canny_th1FLOAT500–1000Lower hysteresis threshold of the INTERNAL Canny. Ignored when canny_aperture_size is 0.
canny_th2FLOAT500–1000Upper hysteresis threshold of the internal Canny. Ignored when canny_aperture_size is 0.
canny_aperture_sizeCOMBO3 (default)Sobel aperture of the internal Canny. '0' skips Canny entirely and treats the input as an edge map, so you can drive FLD from any edge node in the pack.
do_mergeBOOLEANfalseIncrementally merge segments that are collinear and adjacent, so one long edge broken by noise comes back as one segment instead of a chain of pieces.
min_lengthoptFLOAT00–10000Post-filter on the measured length, applied after any merging - length_threshold gates the detector, this gates the RESULT (they differ once do_merge is on). 0 keeps every segment.

Outputs (3)

NameTypeDescription
segmentsNPARRAYNx4 float32 (x1, y1, x2, y2) endpoints - the same layout HoughLinesP and LSD produce, so 'OpenCV Draw Segments' plugs straight in.
lengthsNPARRAY(N,) float32 segment length in pixels.
countINTHow many segments survived - branch on it with if/else for the nothing-found case.