OpenCV matchShapes_1
OpenCV matchShapes_1 — the duplicate contour-similarity scorer, and how to use the score
- contour1
- contour2
- float
matchShapes_1 is matchShapes_0 with a different suffix and zero other differences. Every _0/_1 pair in opencv-comfyui is one OpenCV function declared twice in the type stubs (MatLike and OpenCL UMat) and numbered by the generator instead of merged. Same inputs, same float output, same behavior. Use whichever you grabbed.
What the function does: compares two contours and returns a similarity score. Lower = more similar; 0 = identical. It's largely invariant to translation, scale, and rotation because it compares the contours' moments - their shape statistics - rather than raw point positions. That's the bit worth understanding, because it tells you what the score actually means: "how similar are these two silhouettes as shapes, not as pixel positions."
The inputs
- contour1, contour2 - the two contours as
NPARRAYs. Note these are point lists, not images - don't wireImage2Nparrayoutput into them. And heads up: this pack doesn't ship a contour extractor, so you'll need the contours from another source. - method -
1(CONTOURS_MATCH_I1),2, or3. Start with1. - parameter - legacy tuning;
0.0uses the method's default.
Output is a single FLOAT. Downstream that usually means a threshold or a comparison: "if score < X, these regions are the same shape, do something." Wire it to a float-input node, a threshold, or a condition.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Restart, or ComfyUI Manager → "opencv". Requirements: opencv-contrib-python, numpy, torch.
Troubleshooting
- Contour shape assertions - your contour arrays must be the shape OpenCV expects (a list/array of points). If you're pulling them from the wrong node, you'll see assertion errors with no visual hint.
- "Wait, higher is worse?" - yes.
0is a perfect match; bigger numbers are less similar. Threshold accordingly. - No batch rule here - contours aren't images; the pack's
batch_size==1restriction doesn't apply.
Honest verdict: matchShapes is a solid, old-school shape-matching primitive, and this pack wraps it faithfully. It'll sit unused in 99% of workflows - you need to already be doing contour analysis for it to earn its keep. When you are, matchShapes_0 and matchShapes_1 are the same door.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| contour1 | NPARRAY | — | |
| contour2 | NPARRAY | — | |
| method | INT | — | |
| parameter | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |