OpenCV CV_MAKETYPE_0
The Generic Type-Code Builder (and the Formula Behind All Those CV_* Nodes)
- int
OpenCV CV_MAKETYPE_0 is the generic version of all those CV_8UC_0/CV_64FC_0 nodes. Where they bake in a fixed depth, this one takes depth and channels and computes the OpenCV type constant for any combination: (depth & 7) + ((channels - 1) * 8). It's the underlying formula, exposed directly.
It's part of geroldmeisinger/opencv-comfyui, the auto-generated pack that wraps ~635 top-level cv2 functions as ComfyUI nodes. The author is candid: nodes are generated from type definitions, overloads get numbered, and the README says to expect dragons. For type-code helpers like this one, "dragon" mostly means "you'll rarely open this menu."
The one formula that explains them all
OpenCV encodes an image's data type into a single int by packing a depth value into the low 3 bits and channel count into the rest. The depth constants: CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, CV_64F=6, CV_16F=7. So:
CV_MAKETYPE(0, 3)→0 + 16 = 16, a normal unsigned 8-bit color image (CV_8UC3).CV_MAKETYPE(6, 1)→6, a double-precision float scalar image (CV_64FC1).CV_MAKETYPE(4, 2)→4 + 8 = 12, signed 32-bit, two channels.
The & 7 mask means a depth of, say, 8 wraps around to 0 - you only get three bits of depth, which is all OpenCV allocates. The separate CV_8UC_0, CV_8SC_0, CV_32SC_0, CV_64FC_0 nodes in this pack are just this same node with the depth fixed. If you already know which of those you need, grab the named one; CV_MAKETYPE_0 is for when your depth isn't one of the pre-made shortcuts.
Inputs and outputs
depth(INT) - the depth constant, 0–7 as listed above.channels(INT) - number of channels (1, 3, 4…).int(INT, output) - the packed type code, for feeding downstream nodes that take atypeparameter.
Install
Through ComfyUI Manager (search opencv-comfyui) or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Restart ComfyUI after. No models to download; the pack depends only on numpy, torch, and the OpenCV contrib build from requirements.txt. (Ignore the README's opencv-python-contrib - that's not the package name; opencv-contrib-python is.)
When this bites
Two failure modes worth knowing. First, the 'NoneType' object has no attribute 'shape' error from Nparrays2Image: it means you fed a non-image nparray - a flat float vector or matrix - into the image converter. A hand-built type constant is often the symptom of exactly this, because you've drifted into "matrices, not pictures" territory. Second, ComfyUI's own images are always float32 tensors in 0–1, so a float64 or int32 nparray you built with this node won't behave like a ComfyUI image without the conversion nodes in between. Type codes are OpenCV's language; make sure you're speaking it on the OpenCV side of the Image2Nparray/Nparrays2Image bridge.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| depth | INT | — | |
| channels | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |