OpenCV getRectSubPix_1
Sub-Pixel Cropping, Take Two (Literally the Same Node)
- image
- patch
- nparray
OpenCV getRectSubPix_1 is the duplicate of getRectSubPix_0. The pack generates a node per OpenCV overload, and two of cv2.getRectSubPix's overloads collapsed to the same signature - same four required inputs, same optional out-param, same NPARRAY patch output. There is no behavioral difference. If this is the variant you landed on, everything here applies equally to the _0 one.
What it does
It crops a rectangular patch out of an image, centered on a point that may be fractional - and interpolates. Where a naive crop snaps to whole pixels, getRectSubPix honors a center like (100.3, 75.7) and bilinearly blends the surrounding pixels to synthesize the patch exactly as if the aim were precise. That's its whole reason to exist: sub-pixel-accurate extraction for tracking, optical flow, video stabilization, and template alignment, where a one-pixel rounding error is a real error.
Inputs and outputs
- image (
NPARRAY) - source image (grayscale or color). - patchSize (
STRING) - patch size as a literal,[64, 64](brackets required). - center (
STRING) - center as a literal,[100.3, 75.7](floats welcome - that's the point). - patchType (
INT) - output dtype;-1for same as source,5forCV_32F,6forCV_64F. - patch (
NPARRAY, optional) - the OpenCV out-parameter; ignore it, the output already carries the result. - Output nparray - the extracted patch, and unlike much of this pack it's genuinely a previewable image, so
Nparrays2Imagegets you something to look at.
Two practical notes. The patch is centered on your point, so [64, 64] means center ± 32. And near the image edges OpenCV clamps rather than failing - your patch may silently shift if you point the center too close to the border, which is the one thing that'll quietly bite you.
When you'd bother
Only if you need the precision. For a plain crop, any normal cropping node does the job without the interpolation math. getRectSubPix earns its keep in alignment-heavy pipelines - consistent patch extraction from a moving subject, template-tracking loops, optical-flow preprocessing - where the same feature needs to be sampled at the same fractional location every frame.
Install
Standard pack install - ComfyUI Manager, search opencv-comfyui (display "OpenCV"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Restart, no models. Source images arrive as NPARRAY via Image2Nparray (batch size 1), composite literals need brackets or you'll hit invalid syntax (<unknown>, line 0), and since this node is a pure duplicate, standardize on one variant and don't hunt for differences that don't exist.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY | — | |
| patchSize | STRING | — | |
| center | STRING | — | |
| patchType | INT | — | |
| patchopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |