OpenCV demosaicing_0
Turning Raw Bayer Sensor Data Into a Real Color Image
- src
- dst
- nparray
OpenCV demosaicing_0 reconstructs a full color image from a single-channel Bayer pattern - the raw, per-pixel-sensor output that a camera produces before it becomes an RGB picture. Every digital camera does this internally; this node lets you do it yourself when you're handed raw sensor data instead of a processed frame.
It's one of ~635 auto-generated wrappers in geroldmeisinger/opencv-comfyui, wrapping cv2.demosaicing(src, code, dst, dstCn). If you're doing photogrammetry, feeding raw camera dumps into a pipeline, or simulating camera-pipeline behavior, this is your node. If you're generating images with diffusion, you will never need it - your images arrive demosaiced already.
How it works
A Bayer sensor captures one color per pixel - red, green, or blue - in a repeating 2×2 pattern (RGGB, BGGR, GRBG, GBRG, depending on the sensor). Demosaicing interpolates the missing channels for every pixel, and the code input tells OpenCV which pattern your sensor uses and what output you want:
code(INT) - e.g.cv2.COLOR_BayerBG2BGRfor a BGGR sensor to BGR output. There's a whole family:BayerBG2BGR,BayerRG2BGR, and so on, plus2VNG/2EAvariants with fancier interpolation for better quality at a speed cost. Look up the exact enum in the OpenCV docs.src(NPARRAY) - the raw single-channel Bayer image.dstCn(INT) - output channel count;0infers from the code.dst(NPARRAY, optional) - out-parameter; skip it.nparray(NPARRAY, output) - the reconstructed color image.
Where people get burned
Channel type. demosaicing expects an 8-bit single-channel input. If you feed it something else you'll hit the pack's classic assertion failure, img.type() == CV_8UC1 - the README's shorthand for "give me grayscale, unsigned 8-bit." A raw sensor frame is exactly CV_8UC(1), so it should pass, but if you've already converted or scaled it, fix that first.
Pattern mismatch. Get the Bayer pattern wrong and the image comes out with colors swapped or a weird checkerboard shimmer - that's a code problem, not a bug. If you're pulling raw frames from a camera driver, check what pattern it actually emits.
Install
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. No models. Mind the package name: opencv-contrib-python, not the README's opencv-python-contrib. If Cannot import name 'guidedFilter' from 'cv2.ximgproc' shows up, you have conflicting OpenCV installs - the README links the known fix.
Remember the pack handles batch_size==1 only, so pull a single frame out of any batch before feeding it in.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — | |
| code | INT | — | |
| dstCn | INT | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |