Nodes/opencv-comfyui/OpenCV pencilSketch_0
ComfyUI Node

OpenCV pencilSketch_0

Turning photos into pencil drawings, no model required

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

Want a pencil drawing of your image, instantly, with no model download and no diffusion pass? pencilSketch_0 is OpenCV's cv2.pencilSketch, wrapped as a node - it takes a photo and returns two versions: a grayscale pencil sketch and a color pencil sketch. It's the kind of classic deterministic image-processing primitive that this pack exists to surface, and it's genuinely one of the more fun outputs to drop into a workflow.

Where it actually earns its keep: sketch/lineart-style conditioning. A pencil sketch makes a solid input for ControlNet lineart workflows - you get the rough structure of the subject without the texture, which is often exactly the conditioning signal you want. The KB's ControlNet doc leans on lineart for character consistency, and this is a free, local way to generate that kind of input from any photo.

How it works

cv2.pencilSketch lives in OpenCV's ximgproc extended-modules - which is why this node needs the contrib build of OpenCV, not the plain one. It applies an edge-preserving structure filter (the sigma_s/sigma_r pair) to smooth the image while keeping edges, then derives the sketch lines from the filtered gradients. Two outputs:

  • nparray_0 - the grayscale pencil sketch (dst1)
  • nparray_1 - the color pencil sketch (dst2)

Input should be an 8-bit, 3-channel (BGR) image from Image2Nparray - note this is one of the OpenCV functions that needs a real color image, not a grayscale one.

The inputs that matter

  • src (NPARRAY) - the source image, BGR, from Image2Nparray.
  • sigma_s (FLOAT) - structure smoothing range, roughly 0–200. OpenCV's documented default is 60; larger = smoother.
  • sigma_r (FLOAT) - color/edge sensitivity, 0–1. Default 0.07; smaller keeps more detail.
  • shade_factor (FLOAT) - how dark the shading gets, 0–0.1. Default 0.02.
  • dst1, dst2 (NPARRAY, optional) - OpenCV out-parameters; ignore them. The two outputs above are what you actually use.

A good starting point is the documented defaults: sigma_s = 60, sigma_r = 0.07, shade_factor = 0.02, then nudge shade_factor for line darkness.

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

This node specifically requires the contrib OpenCV: pip install opencv-contrib-python (the README's opencv-python-contrib is the same wheel under an alias). If you only have plain opencv-python, cv2.pencilSketch won't exist. No models to download.

Common issues & troubleshooting

  • "Cannot import name 'guidedFilter' from 'cv2.ximgproc'" - the README flags this exact one: conflicting OpenCV packages in your environment. Multiple custom nodes pin different OpenCV builds; the fix is to settle on one consistent opencv-contrib-python install. The LayerStyle issue the README links has the community walkthrough.
  • (-215:Assertion failed) on a CV_8UC3 check usually means you fed it grayscale or float data - feed it the 3-channel BGR image Image2Nparray produces.
  • Batch rule: batch_size==1 only - use ImageFromBatch if Image2Nparray complains.

Feed the sketch into Nparrays2Image to get back a viewable IMAGE, and you've got a free lineart machine.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
sigma_sFLOAT
sigma_rFLOAT
shade_factorFLOAT
dst1optNPARRAY
dst2optNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY