OpenCV Scharr_0
Sobel's sharper little brother for gradient edges
- src
- dst
- nparray
Scharr_0 wraps cv2.Scharr, which is the answer to the question "how do I get the gradient of an image without smearing the edges?" Sobel's well-known 3×3 derivative filter has a known weakness: at odd kernel sizes it's slightly asymmetric, so the gradient comes out a touch off. The Scharr operator is the 3×3 filter designed to fix exactly that - better rotational symmetry, more accurate gradient magnitude and direction. It's Sobel's sharper little brother, and if you're building edge maps, line art, or normal-ish gradient passes inside ComfyUI, this is the classical filter to reach for before the model does.
How it works
You can think of it as a pre-processing primitive: run it on a grayscale frame and you get a per-pixel gradient that highlights transitions - vertical edges from the x-derivative, horizontal from the y. That's the classic input to Canny-style edge detection, and it's exactly the kind of deterministic operation the KB's post-processing doc puts in the "old, settled, everyone uses it" category. Nobody makes threads about it because it just works.
Inputs and outputs
Inputs, and this is the fiddly part: src (NPARRAY), ddepth (INT), dx and dy (INT), scale (FLOAT), delta (FLOAT), borderType (INT). The rules are strict. dx and dy must sum to 1 - so (1, 0) for the x-gradient or (0, 1) for the y-gradient; anything else errors. For ddepth, the trap is -1 (same depth as src): on a uint8 image that saturates and you get clipped, wrong-looking gradients. Use 5 (CV_32F) or 6 (CV_64F) and take the absolute value, or 2 (CV_16S), the way every OpenCV tutorial does it. borderType default is 4 (BORDER_DEFAULT); you can leave it alone. scale and delta are 1.0 and 0.0 unless you're scaling the output.
Output is a single nparray - the gradient image. The optional dst input is an out-parameter; the README says avoid those, so leave it unwired. And because it wants grayscale input, remember the pack's cvtColor with 6 (BGR2GRAY) on the way in, or you'll hit the README's img.type() == CV_8UC1 assertion.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Install: ComfyUI Manager → search "opencv-comfyui", or the commands above, then pip install opencv-contrib-python for the dependency - no model downloads.
Verdict
Honest take: this is the pack's filter that most deserves a nicer front end - six integer widgets with magic constants where a preset dropdown would do. There are no community threads about it because the whole pack is essentially unheard-of; you're here because you want OpenCV math inside ComfyUI, and for gradient work this is the accurate option. The _0/_1 variants are the MatLike/UMat overloads and behave identically.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| ddepth | INT | — | |
| dx | INT | — | |
| dy | INT | — | |
| scale | FLOAT | — | |
| delta | FLOAT | — | |
| borderType | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |