OpenCV createHanningWindow_0
CreateHanningWindow_0 — a frequency-domain window, for the DFT crowd
- dst
- nparray
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, aSizeliteral, e.g."(64, 64)". Like every composite type in this pack, it's parsed withast.literal_eval, so type the parentheses:(64, 64). Typing64, 64or[64, 64]breaks withinvalid syntax (<unknown>, line 0)- the exact error the pack README's troubleshooting section calls out.type- INT, the output array type constant:5forCV_32F(the sensible default for window math),0forCV_8U, etc. This is where the pack'sCV_32FC_0node is genuinely handy: wireCV_32FC_0(channels=1)→5straight intotypeif 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)→ yourwinSizestring 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 theNoneTypeshape error the README warns about. _0vs_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.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| winSize | STRING | — | |
| type | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |