ComfyUI Node
CV Edge Drawing
Edge Drawing (cv2.ximgproc.createEdgeDrawing): a cv2 CLASS the generated wrappers cannot reach. Instead of thresholding a gradient like Canny, it picks ANCHOR pixels at gradient maxima and walks the ridge between them, so the edge map is one-pixel-wide and already CHAINED - you get the edge SEGMENTS as ordered point runs (CV_CONTOURS), not a pile of lit pixels you have to trace yourself. On top of those chains it fits straight LINES (Nx4, same layout as HoughLinesP / LSD / FLD) and CIRCLES + ELLIPSES (EDCircles), which is the one thing the other line detectors here cannot do. Nothing found is a valid result: every output comes back empty, never None.
CV Edge Drawing
- image
- edge_map
- gradient
- segments
- lines
- ellipses
- segment_count
- line_count
- ellipse_count
◄operatorPrewitt►
◄gradient_threshold20►
◄anchor_threshold0►
◄scan_interval1►
◄min_path_length10►
◄sigma1.0►
◄min_line_length-1►
◄pf_modefalse►
◄nfa_validationtrue►
◄sum_flagtrue►
◄line_fit_error1.0►
◄max_distance_between_two_lines6.0►
◄max_error_threshold1.3►
Categoryimage/CV/contrib
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY,IMAGE | Image to trace (converted to grayscale internally). Feed the ORIGINAL image, not an edge map - ED computes its own gradient. 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. | |
| operator | COMBO | Prewitt | Gradient operator. Prewitt (cv2's default) and Sobel are 3x3; Scharr is the more rotation-accurate 3x3 kernel; 'LSD' switches the whole line stage to the LSD-style detector. |
| gradient_threshold | INT | 201–255 | Pixels with a gradient below this can never be part of an edge. This is the ONE knob that decides how much low-contrast detail is traced; lower = more edges and more noise. |
| anchor_threshold | INT | 00–255 | How much a pixel must exceed its neighbours along the gradient to become an ANCHOR (a seed the tracing starts from). 0 anchors every local maximum, which is cv2's default; raising it thins the result to the strongest edges. |
| scan_interval | INT | 11–32 | Anchors are only looked for every Nth row/column. 1 scans everything; higher is faster and misses short edges. |
| min_path_length | INT | 100–10000 | Edge chains shorter than this many pixels are dropped - the declutter knob for the SEGMENTS output. |
| sigma | FLOAT | 1.00–10 | Gaussian blur applied before the gradient. Raise it on noisy images; 0 disables the smoothing. |
| min_line_lengthopt | INT | -1-1–10000 | Shortest line the line stage will fit, in pixels. -1 (cv2's default) derives it from the image size. |
| pf_modeopt | BOOLEAN | false | Parameter-Free mode: ED validates every edge with the Helmholtz principle instead of the gradient threshold, so the result stops depending on the knobs above. Slower, and the usual choice when you are after ELLIPSES. |
| nfa_validationopt | BOOLEAN | true | Validate fitted lines and ellipses with the number-of-false-alarms test. Off returns more, less trustworthy fits. |
| sum_flagopt | BOOLEAN | true | Gradient magnitude as |gx| + |gy| (on, cv2's default) instead of the exact hypot. |
| line_fit_erroropt | FLOAT | 1.00–10 | Maximum RMS error, in pixels, for a piece of chain to be accepted as one straight line. |
| max_distance_between_two_linesopt | FLOAT | 6.00–100 | Two collinear line pieces farther apart than this are not merged (used by the ellipse fitting too). |
| max_error_thresholdopt | FLOAT | 1.30–10 | Maximum fit error accepted when circular arcs are joined into a circle or an ellipse. |
Outputs (8)
| Name | Type | Description |
|---|---|---|
| edge_map | NPARRAY | uint8 (H,W) mask, 255 on the traced edges - one-pixel-wide by construction. Feed it to 'CV Array -> Mask' or to any node that takes a Canny result. |
| gradient | NPARRAY | uint16 (H,W) gradient magnitude ED computed - preview it with 'Preview CV Array' (normalize). |
| segments | CV_CONTOURS | The edge CHAINS as CV_CONTOURS (one ordered Nx1x2 int32 point run each) - draw them with 'OpenCV Draw Contours' or measure them with the contour nodes. These are open curves, so area is meaningless; length is not. |
| lines | NPARRAY | Nx4 float32 (x1, y1, x2, y2) straight fits - same layout as HoughLinesP / LSD / FLD, so 'CV Draw Segments' plugs straight in. |
| ellipses | NPARRAY | Nx5 float32 (cx, cy, semi_axis_a, semi_axis_b, angle_deg) - circles come back with a == b and angle 0. Draw them with 'CV Draw Ellipses'. |
| segment_count | INT | How many edge chains were traced. |
| line_count | INT | How many straight lines were fitted. |
| ellipse_count | INT | How many circles + ellipses were fitted - branch on it with if/else, 0 is a normal outcome on a scene with no round objects. |