Canny边缘检测
Canny edge detection in FlowCV
- 图像输入
- 图像输出
Canny is the classic edge detector - the one that turns a photo into a clean, thin outline map, and it's been the default answer to "find the edges" in computer vision for over 30 years. FlowCV's FCV_Canny node (menu label Canny边缘检测) wraps OpenCV's implementation so you can drop it into a ComfyUI graph without leaving CVIMAGE space. If you've used a Canny ControlNet preprocessor before, you already know the look: white lines on black, one-pixel-ish, unambiguous.
Why you'd use it here
In a generation workflow you'd reach for this when you want a structural edge map for conditioning - Canny output feeding a ControlNet is the classic route, and it's also great for building masks, finding contours, or cleaning up an image before FCV_FindRectangles. The KB's ControlNet notes call Canny "the classic... best for architectural images, mechanical objects, and scenes with clear contours" - that's the sweet spot. It's also dramatically cheaper than the bundled deep-learning preprocessors; this is pure OpenCV math, no model, runs in milliseconds.
How it works
The node converts your image to grayscale, then runs cv2.Canny() - a multi-stage pipeline: Gaussian smoothing to kill noise, Sobel gradients to measure intensity change, non-maximum suppression to thin the edges to one pixel, then double-threshold hysteresis to decide which candidate edges survive. That last stage is what the two big inputs control:
- 低阈值 (low threshold, default 50) - gradient strength above this starts an edge.
- 高阈值 (high threshold, default 150) - gradient strength above this definitely counts. Edges between the two survive only if they connect to a strong edge.
The classic rule of thumb is high ≈ 2–3× low, which the defaults already follow (150/50). The node even protects you from a silly config: if 高阈值 ends up ≤ 低阈值, it silently rewrites them to 低阈值 + 50.
The other two inputs are 核大小 (Sobel kernel size, 3/5/7 - 3 is standard and fine) and L2梯度 (否/是), which switches between the faster L1 and the more accurate L2 gradient norm. Leave both alone until you're chasing edge quality on a specific image.
Output and wiring
Output is a binary edge map as a CVIMAGE. The node converts grayscale to 3-channel BGR on the way out to keep the pack's types consistent - but note the edges are white-on-black in that "gray" image, so don't expect colors. Send it to FCV_CVToIMAGE to preview or to feed a ControlNet/mask workflow, or straight into FCV_FindRectangles when you're locating shapes.
Installing
It's bundled in FlowCV, so install the pack once - ComfyUI Manager (search "FlowCV") or:
cd ComfyUI/custom_nodes
git clone https://github.com/Koren-cy/FlowCV
Restart. Dependencies are just opencv-python, numpy, and pyserial; nothing to download. Fair warning from the README: the project has migrated to ComfyUI_For_Academic, so this repo is effectively archived.
Gotchas
Edges come out noisy on textured images - run FCV_Gaussian or FCV_Median on the input first if the map is a mess. And remember the pack's silent-failure quirk: an exception prints a Chinese error to the console and returns the input unchanged. Output looks like it never processed? Check the terminal, not the canvas.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像输入 | CVIMAGE | 输入的openCV格式图像 | |
| 低阈值 | INT | 500–255 | Canny算法的低阈值,用于连接边缘 |
| 高阈值 | INT | 1500–255 | Canny算法的高阈值,用于检测强边缘 |
| 核大小 | COMBO | 3 | Sobel算子的核大小,用于计算梯度 |
| L2梯度 | COMBO | 否 | 是否使用L2梯度计算方式(更精确但计算量大) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| 图像输出 | CVIMAGE | Canny边缘检测处理后的图像 |