Nodes/opencv-comfyui/OpenCV flip_0
ComfyUI Node

OpenCV flip_0

Mirror or flip an image with one integer

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV flip_0
  • src
  • dst
  • nparray
flipCode

Sometimes a generation comes out backwards. Sometimes you're compositing and the reflection has to mirror. Sometimes you've got a webcam feed and a live-mirror effect is the whole point. flip_0 is the OpenCV flip function with the serial numbers filed off: one input image, one integer, one flipped image out. It's about as simple as this pack gets.

That's worth saying, because this is the auto-generated OpenCV pack, and most of its nodes are the opposite of simple. flip_0 isn't one of them. It does exactly one thing and does it instantly - it's a deterministic pixel operation in the same bucket as all the post-processing primitives the KB calls "the $0, millisecond, deterministic operation" layer: no model, no seed, no surprises.

How it works

OpenCV's flip mirrors the array along an axis. The whole control surface is the flipCode, and the convention trips people up once:

  • 0 - flip vertically: upside-down (around the horizontal axis).
  • 1 - flip horizontally: left-right mirror (around the vertical axis).
  • -1 - flip both: 180° rotation.

Yes, the naming feels backwards. 0 flips vertically, 1 flips horizontally. You'll mix it up on the first try; everyone does.

Inputs and outputs

  • src (NPARRAY) - the image to flip, as an OpenCV array (go through Image2Nparray first).
  • flipCode (INT) - 0, 1, or -1 as above. That's the whole decision.
  • dst (NPARRAY, optional) - an OpenCV out-parameter. Per the README's standing advice, ignore it; you don't need it.

Output is nparray - the flipped image, ready for Nparrays2Image and whatever comes next in your pipeline.

Installing

Part of geroldmeisinger/opencv-comfyui. ComfyUI Manager: search "opencv-comfyui". Or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart ComfyUI afterward. The pack's requirements.txt pulls opencv-contrib-python, numpy, and torch - pip install opencv-contrib-python if you're on a bare install.

Common issues

The usual pack rules apply: Image2Nparray only accepts batch_size==1, and the whole pipeline is IMAGE → Image2Nparray → this → Nparrays2Image → IMAGE. If you skip the conversion and feed it a Comfy tensor directly, you'll get type errors.

And the one genuine trap: if your flip looks wrong rather than flipped - colors swapped, weird channels - you've skipped cvtColor or the conversion nodes somewhere. This pack works in BGR like OpenCV, not RGB like Comfy, and Nparrays2Image expects its input back in BGR. Flip is dumb in the good way: it mirrors pixels and doesn't touch color, so the only way to break it is to feed it the wrong format.

One more thought: for a one-off mirror you might prefer a node from a friendlier pack. But if you're already in the OpenCV graph - say, flipping video frames between other cv2 operations - this is the native move, and it's free.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
flipCodeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY