ComfyUI Node
CV Detect Line Segments (LSD)
Line Segment Detector (cv2.createLineSegmentDetector): finds straight edge segments with SUBPIXEL endpoints and a measured width, in one pass, with no threshold to tune. Unlike cv2_HoughLinesP it works on the gradient field directly - no Canny step, no accumulator resolution, and each segment is a real, bounded piece of edge rather than a vote peak, so it does not fuse two collinear edges into one line. LSD is a cv2 class the raw wrappers cannot expose. Output is the same Nx4 (x1, y1, x2, y2) layout HoughLinesP produces, so 'CV Draw Segments' plugs straight in. Finding nothing is a valid result (count = 0, empty arrays), never an error.
CV Detect Line Segments (LSD)
- image
- segments
- widths
- lengths
- nfa
- count
◄refinestandard►
◄scale0.80►
◄sigma_scale0.60►
◄quant2.0►
◄angle_tolerance22.5►
◄density_threshold0.70►
◄min_length0►
◄log_eps0.0►
◄bins1024►
Categoryimage/CV/features
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY,IMAGE | Image to search (converted to grayscale internally); feed the ORIGINAL image, not an 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. | |
| refine | COMBO | standard | Refinement level. 'standard' splits arcs and refines endpoints; 'advanced' additionally validates each segment with the NFA (number of false alarms) test and fills the 'nfa' output; 'none' is the raw, fastest pass. |
| scale | FLOAT | 0.800.1–2 | Image is downscaled by this factor before detection. Below 1.0 suppresses noise and speeds things up; 1.0 keeps full resolution and finds more short segments. |
| sigma_scale | FLOAT | 0.600.1–2 | Gaussian blur sigma used for the downscale, expressed as sigma = sigma_scale / scale. |
| quant | FLOAT | 2.00–20 | Bound on the gradient quantisation error; raise it on noisy or heavily compressed images. |
| angle_tolerance | FLOAT | 22.51–90 | Gradient angle tolerance in DEGREES for pixels to join the same line-support region. |
| density_threshold | FLOAT | 0.700–1 | Minimum density of aligned pixels inside a segment's enclosing rectangle; lower accepts sparser segments. |
| min_lengthopt | FLOAT | 00–10000 | Post-filter: drop segments shorter than this many pixels. 0 keeps every segment. LSD has no length knob of its own, and short segments are what clutters a result. |
| log_epsopt | FLOAT | 0.0-10–10 | Detection threshold for the 'advanced' NFA test: -log10(NFA) > log_eps. Only used when refine is 'advanced'. |
| binsopt | INT | 10241–8192 | Number of bins in the gradient-modulus pseudo-ordering. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| segments | NPARRAY | Nx4 float32 (x1, y1, x2, y2) subpixel endpoints - feed 'CV Draw Segments' directly. |
| widths | NPARRAY | (N,) float32 measured width of each segment in pixels. |
| lengths | NPARRAY | (N,) float32 segment length in pixels - use it with a comparison node to keep only the long structural edges. |
| nfa | NPARRAY | (N,) float32 -log10(number of false alarms) per segment (higher = more certain). All zeros unless refine is 'advanced', which is the only mode that computes it. |
| count | INT | How many segments survived - branch on it with if/else for the nothing-found case. |