Nodes/opencv-comfyui/OpenCV CV_16FC_0
ComfyUI Node

OpenCV CV_16FC_0

CV_16FC_0 — a type-constant calculator, and the code it saves you

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV CV_16FC_0
    • int
    channels

    CV_16FC_0 is a node that computes one of OpenCV's internal type constants: cv2.CV_16FC(channels). It takes a single channels INT and returns the INT that encodes "16-bit float (CV_16F), N channels." That's it. It's not image processing - it's a calculator for the numeric codes OpenCV uses to describe array types, and the only reason it exists is that the pack's generator wrapped every top-level cv2 function, including the type macros.

    Here's the context that makes this node make sense. OpenCV packs a matrix's element type into one integer: the low bits encode the depth (CV_16F = 7, CV_32F = 5, CV_8U = 0, etc.) and the next bits encode the channel count. The formula is:

    type = depth + (channels - 1) × 8

    So CV_16FC(1) = 7, CV_16FC(2) = 15, CV_16FC(3) = 23, CV_16FC(4) = 31. A few functions in this pack want a type constant as an input (like createHanningWindow_0's type param, or anything with a dstType), and if you don't want to memorize the table, you compute it. In Python you'd write cv2.CV_16FC(3); in a ComfyUI graph, the only place to "write code" is a node like this one.

    When you'd actually use it

    Narrow, but real. If a node in your graph takes an OpenCV type constant and you need a 16-bit float array - which you'd want for high-dynamic-range or precision intermediate math, e.g. HDR-style operations or anything that needs more range than uint8 - feed the constant from here. The honest framing: CV_16F is a niche depth. You're doing float16 matrix work in OpenCV-land, which is unusual enough that this node will mostly sit unused next to the pack's more mainstream CV_32FC_0. When you do need it, it's the difference between typing 23 from memory and having the node hand it to you.

    The spec

    • channels - INT, the channel count you want the type for. 1–4 are the useful range (CV_16FC1CV_16FC4); OpenCV supports more, but arrays with 5+ channels are vanishingly rare.
    • Output: int - the type constant (7 for 1 channel, 15 for 2, 23 for 3, 31 for 4).

    Install

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

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

    Restart. Needs opencv-contrib-python, numpy, torch. No models.

    Anything to watch?

    The _0 here isn't the overload twin you see elsewhere - CV_16FC is a single function in the type defs, so there's no _1. And don't confuse it with CV_16UC_0 (unsigned 16-bit int) or CV_16SC_0 (signed) - same shape, different depth codes. If your downstream node complains about a type, double-check you fed it the constant for the right depth. Everything else about this node is as boring as a calculator, which is precisely the point.

    Categoryimage/OpenCV

    Inputs (1)

    NameTypeDefaultDescription
    channelsINT

    Outputs (1)

    NameTypeDescription
    intINT