Nodes/opencv-comfyui/OpenCV pencilSketch_1
ComfyUI Node

OpenCV pencilSketch_1

The identical twin — and why this node is the one that breaks installs

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV pencilSketch_1
  • src
  • dst1
  • dst2
  • nparray_0
  • nparray_1
sigma_s
sigma_r
shade_factor

pencilSketch_1 is the UMat twin of pencilSketch_0 - same signature, same cv2.pencilSketch call, same outputs. The full how-to lives in the pencilSketch_0 article; this page covers the ground plus the one thing that genuinely trips people up: this family of nodes is why your ComfyUI install might have OpenCV import errors.

cv2.pencilSketch lives in ximgproc, part of the contrib build of OpenCV. The README's troubleshooting section calls out the failure mode directly: Cannot import name 'guidedFilter' from 'cv2.ximgproc'. That error is a dependency conflict - some other custom node pulled in a plain opencv-python (no contrib), or two OpenCV packages are fighting in your environment - and it surfaces the moment anything tries to load the contrib modules pencilSketch needs. The linked LayerStyle issue has the community's fix, but the short version is: unify on a single opencv-contrib-python install and let pip resolve everything to one build. This is exactly the "dependency hell" the ecosystem docs describe as the #1 operational complaint about custom nodes.

What the node does

Takes a BGR image from Image2Nparray and produces a pencil sketch via the sigma_s/sigma_r/shade_factor structure-filter parameters. Outputs nparray_0 (grayscale sketch) and nparray_1 (color sketch). Documented starting defaults: sigma_s = 60, sigma_r = 0.07, shade_factor = 0.02. The grayscale output is a handy free source of lineart-style conditioning for ControlNet.

The inputs that matter

  • src (NPARRAY) - BGR image, 8-bit, 3-channel.
  • sigma_s, sigma_r, shade_factor (FLOAT) - the three style dials above.
  • dst1, dst2 (NPARRAY, optional) - out-parameters; ignore them.

Outputs: nparray_0 (gray sketch), nparray_1 (color sketch).

How to install it

Pack-level install, once:

  • ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
  • Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Then make sure the contrib OpenCV is the one that wins: pip install opencv-contrib-python.

Common issues & troubleshooting

  • guidedFilter import error - the contrib conflict described above. Fix the OpenCV install, not the node.
  • (-215:Assertion failed) - you fed it grayscale or non-8-bit input; use the BGR image Image2Nparray outputs.
  • Batch rule: batch_size==1 only - pull a frame with ImageFromBatch if needed.

Same node as _0. The interesting part of this page isn't the node - it's the OpenCV dependency story hiding behind it.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
sigma_sFLOAT
sigma_rFLOAT
shade_factorFLOAT
dst1optNPARRAY
dst2optNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY