cv2.CV_16SC
The type code behind fast fixed-point remapping
- int
Of all the type-code nodes in bmad4ever's ComfyUI CV pack, cv2.CV_16SC is the one with a real job: CV_16SC2 is the fixed-point map format that makes cv2.remap fast, and it's the format stereo rectification produces. If you've ever seen a map-type dropdown offering "CV_16SC2 (fixed-point, faster remap)" next to "CV_32FC1 (float32, standard)", this node is how you feed that parameter.
Like its siblings, it's a builder, not a converter. One INT input (channels), one INT output (int), wrapping OpenCV's CV_16SC(channels) macro. The macro packs depth and channel count into a single integer: CV_16S is depth 3, and each extra channel adds 8, so CV_16SC(2) is the type code for the two-channel signed-16-bit map that cv2.convertMaps and cv2.initUndistortRectifyMap can emit.
Why 16-bit signed
Because a remap table is not pixels. A two-channel 16SC map stores, per output pixel, the source position as fixed-point integers - whole-pixel coordinates with only a few fractional bits retained, instead of a full float32 pair. That's half the memory per output pixel and a dedicated fast path in cv2, which matters when you're remapping video frames or doing stereo rectification on every frame rather than once.
Signed also earns its place for values that legitimately go negative: difference images, disparity before scaling, gradient channels. For 16-bit unsigned there's cv2.CV_16UC; for plain depth maps and stereo disparity storage, that's usually the one you want.
The pack's own dropdowns are a good map of where 16SC shows up: cv2.convertMaps's dstmap1type, and m1type on cv2.initUndistortRectifyMap / cv2.initInverseRectificationMap. In each case the field wants a type code, and the two sane answers are 16SC2 (fast, quantised) or 32FC1 (float, exact). Those are the two options the pack's preset enum offers, which tells you the author has already made the decision for you in the dropdown - this node is for when you're driving the parameter from elsewhere.
The inputs and outputs that matter
channels is an INT and the default is 0, which is not a valid channel count - the macro computes channels − 1, so 0 produces a nonsense (negative) code. Set 2 for a map pair, 1 for a plain image depth.
The output is a plain INT socket named int. To use it, convert the receiving widget to an input on the target node first (right-click the widget → Convert widget to input), then wire. If you're hand-computing the number anyway, remember CV_16SC2 is just 11 - depth 3 plus one channel step of 8 - and typing that is faster than building it. There's no shame in that; the pack exposes every top-level cv2 function whether or not you need it (the README is explicit that the ~470 wrappers are auto-generated and uncurated).
Don't reach for it expecting an array conversion: CV Cast Array changes an array's dtype, CV DType reports the dtype name as a string, and this node only produces the integer code.
Installing it
ComfyUI Manager → search the pack title (ComfyUI CV) → install → restart. Manual:
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 V3-API ComfyUI; the whole pack is written against that schema, so an old ComfyUI fails outright rather than degrading. Because the node registry is generated from the installed cv2, any constant your build doesn't expose simply won't have a node - and if you install a non-contrib opencv-python over the contrib wheel, the shared site-packages/cv2 loses its contrib submodules and a chunk of nodes disappears without an error naming the cause. tools/repair_opencv_contrib.py --check then --apply is the fix.
Common issues and troubleshooting
A negative output. channels is still 0. Set 1 or 2.
The receiving node rejects the link. Its widget isn't a socket yet - convert it to an input first.
You picked 16SC2 and the remap looks blockier. That's the fixed-point quantisation doing its job: map positions snap to the nearest representable fraction of a pixel. On a big zoom or a warp where sub-pixel exactness matters, switch the map type to CV_32FC1 and pay the memory.
cv2.remap complains about the map. Two-channel 16SC maps expect a specific layout - if you built the map yourself, remember it's a single two-channel array, not two separate planes of the wrong dtype.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| channels | INT | 0-2147483648–2147483647 | - - - |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |