cv2.CV_MAKETYPE
Build an OpenCV type code from depth + channels
- int
cv2.CV_MAKETYPE is the useful member of the CV_* constant family: two INT inputs (depth and channels), one INT output, and it composes the OpenCV type code that names a matrix - "float32, three channels", "uint8, one channel" - as a single number. It's the factory the other CV_8UC/CV_32FC-style nodes are shorthand for.
The mechanism, and the one thing that trips everyone
type_code = depth + ((channels - 1) << 3)
depth is a depth code, not a type code. The classic set is worth memorising because it shows up in every cv2 assertion: CV_8U = 0, CV_8S = 1, CV_16U = 2, CV_16S = 3, CV_32S = 4, CV_32F = 5, CV_64F = 6. Channel count goes in the high bits, three bits per step.
So the composed values you'll actually see are:
| depth | channels | result | the name for it |
| --- | --- | --- | --- |
| 0 | 1 | 0 | CV_8UC1 |
| 0 | 3 | 16 | CV_8UC3 |
| 5 | 1 | 5 | CV_32FC1 |
| 5 | 3 | 21 | CV_32FC3 |
| 6 | 1 | 6 | CV_64FC1 |
Where people get burned: feeding depth a complete type code. CV_8UC(3) is 16; pass 16 here and you've told OpenCV "depth 16" - garbage. If you're chaining the constant nodes, take CV_8UC(1) (= CV_8U = 0) or CV_32FC(1) for the depth, and let this node add the channels. The plain single-channel member of each family is the depth.
The second trap is the defaults: both inputs come in at 0, which is a valid depth but not a valid channel count. CV_MAKETYPE(0, 0) isn't a type anything accepts. Set both.
Outputs, and where the number goes
One int output. Realistically it goes into another INT parameter in this pack that takes a raw type number - the same niche as the other constant nodes. Most of the pack's depth-ish inputs (ddepth on cv2.Sobel, dtype on cv2.reduce, m1type on cv2.initUndistortRectifyMap) are curated dropdowns with human-readable options that resolve the constant themselves, so you don't need a number there.
The value of the node is mostly as a decoder: run it, read the number, and now (-215) ... CV_32FC3 in your console means 21. Half of debugging a low-level cv2 graph in ComfyUI is learning to read those codes.
You can do the same without ComfyUI - the node is a thin wrapper over this call:
python3 -c "import cv2; print(cv2.CV_MAKETYPE(cv2.CV_32F, 3))"
# 21
Install
Manager → Install Custom Nodes → search ComfyUI CV (publisher bmad4ever), or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Restart ComfyUI after. Python ≥ 3.12 and a recent V3-API ComfyUI are required; the contrib headless wheel is the only dependency, and this node needs no models. If contrib nodes have vanished from the pack, a plain opencv-python install has overwritten the shared cv2 binary - python tools/repair_opencv_contrib.py --check then --apply fixes it. The pack is GPL-3.0 (a fork of geroldmeisinger/opencv-comfyui), largely AI-written, and the author says outright it isn't production-ready and that support is not on offer.
Common issues
- A downstream cv2 node raises an unhelpful "Overload resolution failed". Usually not this node - that's cv2 rejecting a float where it wants an int. But if a type parameter is involved, print the code you built and sanity-check it against the table above.
- The node isn't in your list. Every wrapper is resolved against your installed
cv2at import and skipped if absent.CV_MAKETYPEis core, so a missing node means the pack itself failed to load - check the console and your Python version. - You expected a dropdown list of types. That's the curated depth widgets elsewhere in the pack. This is the raw call.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| depth | INT | 0-2147483648–2147483647 | - - - |
| channels | INT | 0-2147483648–2147483647 | - - - |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |