cv2.CV_32SC
The type code behind label maps and index arrays
- int
cv2.CV_32SC builds the signed-32-bit type code - the one OpenCV uses for label maps and indices. It's the node cv2.CV_32SC in bmad4ever's ComfyUI CV pack: one INT widget (channels), one INT output (int), wrapping the CV_32SC(channels) macro. Nothing is converted; it just produces the integer code.
The reason this code deserves a node is that you meet 32S arrays in the middle of a graph whether or not you asked for them. cv2.connectedComponents and its variants return a label image where every pixel holds the index of its blob - type CV_32S. cv2.findNonZero returns a point list as CV_32S. Watershed markers are CV_32S. And the meaning of those values is an identifier, not a brightness: 4 doesn't mean "dark", it means "component number four".
That distinction is the practical trap. Send a label map through an IMAGE bridge and you get a meaningless false-colour picture, because the bridge faithfully reinterprets identifiers as intensities. In this pack the correct route is the other one - CV Labels to Masks (full size) turns a label map into one MASK per region, CV Region Properties reports per-label statistics, and CV Colorize Model-style visualisation nodes exist for when you do want to look at labels as colours.
How the code works
As with every type code in OpenCV, depth and channel count are packed into a single integer: depth + ((channels − 1) << 3). CV_32S is depth 4, so CV_32SC(1) is 4 and each extra channel adds 8. Label maps are one-channel, so in practice you set channels = 1 and move on.
The channels widget's default is 0, which is not "one channel" - the macro computes channels − 1 and a zero underflows into a negative code that no cv2 function will take. That default is on every one of these constant nodes; treat it as a field you must fill, not a value.
The output is a plain INT socket. ComfyUI only lets you wire into inputs, so the receiving node's dtype or ddepth widget has to be converted first: right-click it → Convert widget to input. In practice you're passing this to a dtype on arithmetic (cv2.add, cv2.multiply, cv2.subtract, cv2.reduce, cv2.normalize) when you want the result to stay in integer label space instead of being promoted to float. Either that, or you're just typing the number - the pack's wrappers expose integer params as plain widgets precisely because there's no closed list, and the README says the ~470 wrappers are generated mechanically rather than curated.
Worth knowing the neighbours: cv2.CV_16SC covers the signed 16-bit code (and the fixed-point CV_16SC2 map format), cv2.CV_8UC the plain 8-bit unsigned one, and CV Cast Array / CV DType are the nodes that actually convert or report dtypes - a code builder like this changes nothing on its own.
Installing it
Manager → search the pack title (ComfyUI CV) → install → restart ComfyUI. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Python ≥ 3.12 and a ComfyUI recent enough for the V3 node API. The registry is generated against your installed cv2, so a constant a build doesn't expose gets no node at all - if cv2.CV_32SC isn't in your node list, that's the reason, not a failed install. And keep the contrib wheel in charge: installing a non-contrib opencv-python on top of it silently empties the contrib submodules in the shared site-packages/cv2, and contrib nodes disappear until you run tools/repair_opencv_contrib.py --apply.
Common issues and troubleshooting
Output is negative. channels left at 0 → set 1.
The link won't attach. The destination is still a widget. Convert it to an input first.
Labels look like noise after a bridge. You sent identifiers through a visual conversion. Keep label maps in NPARRAY space and use CV Labels to Masks or CV Region Properties instead of an IMAGE conversion.
32-bit indices arriving as floats. Some operations promote integer types. If a downstream node insists on integer input, check the dtype with CV DType and cast with CV Cast Array rather than hoping.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| channels | INT | 0-2147483648–2147483647 | - - - |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |