Nodes/opencv-comfyui/OpenCV setRNGSeed_0
ComfyUI Node

OpenCV setRNGSeed_0

Make OpenCV's randomness reproducible

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV setRNGSeed_0
    • unknown
    seed

    setRNGSeed_0 seeds OpenCV's internal random number generator. One integer in, no output, done. It's the "make it deterministic" switch for any OpenCV function that rolls dice.

    Here's the context that makes it useful: this pack wraps the standalone cv2 functions, and a handful of them are random. cv2.rand, cv2.randn, cv2.randShuffle fill or shuffle arrays with randomness. Functions like rand and randn are exactly the kind of thing someone building a synthetic-data or noise pipeline inside ComfyUI would reach for - and without a seed, every run gives you different noise. Seed it once and the noise becomes reproducible, which matters when you're comparing two workflows and need the input noise to be identical between runs.

    The mechanism is one line: cv2.setRNGSeed(seed) resets the process-wide RNG that those functions draw from. Nothing else. The seed input is just the integer you want; anything works, and re-running with the same seed reproduces the same random outputs from OpenCV's random functions.

    The output is None - the schema literally names it unknown because the function returns nothing. There's no wiring to do; you drop this node into the graph so it executes before the random functions.

    Now the caveat that matters, because people assume too much here: this seeds only OpenCV's own C++ RNG. It does not touch numpy's default_rng, it does not touch Python's random module, and it does not touch torch - which is what ComfyUI uses for its own seeds, sampling, and most noise generation. If your workflow's randomness comes from KSampler or a noise node, this node does nothing for you; ComfyUI's own seed inputs are the thing to set. It's purely for OpenCV-native random operations.

    Also note it's a global setting that persists for the rest of the process, and ComfyUI doesn't guarantee node execution order matches the canvas. So don't build a workflow where one branch sets the seed and another depends on "running after." Set it once at the start with a fixed value.

    Install: ComfyUI Manager → search "opencv-comfyui", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes and restart. Requires opencv-contrib-python (numpy/torch are already there). If startup fails with Cannot import name 'guidedFilter' from 'cv2.ximgproc', a conflicting OpenCV from another node is the culprit - uninstall the duplicate.

    Bottom line: a niche node for a niche situation. If you're generating reproducible OpenCV noise or shuffles inside a workflow, it's the tool. If you're trying to make your image generation reproducible, you want ComfyUI's own seed handling - this node won't help you there, and it's important to know the difference.

    Categoryimage/OpenCV

    Inputs (1)

    NameTypeDefaultDescription
    seedINT

    Outputs (1)

    NameTypeDescription
    unknownNone