Nodes/opencv-comfyui/OpenCV createHanningWindow_0
ComfyUI Node

OpenCV createHanningWindow_0

CreateHanningWindow_0 — a frequency-domain window, for the DFT crowd

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV createHanningWindow_0
  • dst
  • nparray
winSize
type

createHanningWindow_0 wraps cv2.createHanningWindow, which builds a 2D Hanning window - a smooth, bell-shaped weighting matrix used before you run a Fourier transform. It's a one-line utility in OpenCV and a niche node in ComfyUI, so let's be straight about who this is for: you, if your workflow touches frequency-domain work. That means phase correlation for image alignment, DFT-based filtering, optical-flow-style analysis, or spectral processing of frames. If none of that is your life, this node is genuinely skippable - it produces a weighting matrix, not an image, and you won't miss it.

But when you need it, it's the difference between a clean spectrum and one that leaks: taking a DFT of a raw image makes the edges dominate the frequency content (the classic "spectral leakage"). Multiplying by a Hanning window first tapers the edges to zero so the transform represents the content, not the frame boundary. In a frame-alignment or motion-estimation pipeline inside ComfyUI, that's the standard pre-DFT step.

How it works

The window is the product of a 1D Hanning (von Hann) curve along each axis - 0.5 · (1 − cos(2πn/(N−1))) - tiled into 2D. The output is a float array of your requested size, shaped to winSize, which is not a viewable image. It's a mask to multiply against an image before dft/phase-correlation work.

The inputs - and the string trap

  • winSize - STRING, a Size literal, e.g. "(64, 64)". Like every composite type in this pack, it's parsed with ast.literal_eval, so type the parentheses: (64, 64). Typing 64, 64 or [64, 64] breaks with invalid syntax (<unknown>, line 0) - the exact error the pack README's troubleshooting section calls out.
  • type - INT, the output array type constant: 5 for CV_32F (the sensible default for window math), 0 for CV_8U, etc. This is where the pack's CV_32FC_0 node is genuinely handy: wire CV_32FC_0(channels=1)5 straight into type if you can't remember constants.
  • dst - optional out-parameter; leave it unconnected, per the README.

Output: one nparray - the window. Not an image.

Install

Part of opencv-comfyui (geroldmeisinger). ComfyUI Manager → search opencv-comfyui → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart. Requirements: opencv-contrib-python, numpy, torch. No model downloads.

Common issues

  • invalid syntax (<unknown>, line 0) → your winSize string isn't a valid Python literal. Use (64, 64).
  • Output "looks wrong" when previewed → it's a weighting matrix, not a picture. If you force it through Nparrays2Image, expect the NoneType shape error the README warns about.
  • _0 vs _1 → identical overloads; either works.

The pack is auto-generated and blunt - "expect dragons" - and this node is squarely in the "utility for a specialist stage" bucket. Know whether your pipeline does DFT work before you reach for it; if it does, this is the boring, correct windowing primitive that keeps your spectrum honest.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
winSizeSTRING
typeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY