Nodes/opencv-comfyui/OpenCV pointPolygonTest_0
ComfyUI Node

OpenCV pointPolygonTest_0

Is that point inside the region? Hit-testing with OpenCV pointPolygonTest_0

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV pointPolygonTest_0
  • contour
  • float
pt
measureDist

pointPolygonTest_0 is a tiny question-answering node: give it a polygon and a point, and it tells you whether the point is inside, outside, or exactly on the polygon. That's the whole job, and it's a job with more uses in ComfyUI than you'd think.

It comes from opencv-comfyui, the auto-generated pack that wraps hundreds of standalone OpenCV functions as nodes - no models, no downloads, no API keys. The author, Gerold Meisinger, warned on r/comfyui when he shipped it in April 2025 that the nodes are thin wrappers and "ugly and complex to use. Expect dragons!" True enough, but pointPolygonTest_0 is one of the cleaner ones: two inputs, one output, nothing subtle about the semantics.

How it works

OpenCV's pointPolygonTest measures the distance from a point to a contour, and the sign tells you the side:

  • Positive - the point is inside the polygon.
  • Negative - outside.
  • Zero - exactly on the boundary.

The measureDist boolean decides how precise the answer is. Set it False and you get a cheap ternary: 1 inside, -1 outside, 0 on the edge. Set it True and the node computes the actual signed distance in pixels - so +12.5 means "12.5 pixels inside the nearest edge", which is genuinely useful when you care how deep a point sits inside a region, not just that it does.

The inputs that matter

  • contour (NPARRAY) - the polygon itself, in the form OpenCV contour functions produce: shape (N, 1, 2) or (N, 2). If you've got a mask instead, extract its contour first with findContours (also in this pack) before wiring it here.
  • pt (STRING) - this is the trap. The point is a composite OpenCV type, and this pack handles composite types as Python literals typed into a text box. So you enter the point as (x, y), literally with parentheses: (512, 384). If you type 512, 384 or [512, 384] you'll get the "invalid syntax" error the README warns about.
  • measureDist (BOOLEAN) - cheap sign check or full distance. Start False; switch to True only when you need the pixel distance.

The single output is a float.

What you'd actually use this for

The practical ComfyUI use case is guarding a branch. Say you have a detection pipeline (SAM, a face detector, a YOLO box) and you only want to inpaint or detail a region when the detected point actually lands inside a defined polygon - a crop boundary, a face area, a fixed region you don't want touched. Wire the point-in-polygon result into a logic or switch node and you've got data-driven routing: "inpaint only if the face is inside the mask." That's the classic hit-test, and it costs milliseconds.

It's also handy for sanity-checking masks: feed a mask's centroid and the mask's own contour, and a positive distance confirms the mask is well-formed.

Install and gotchas

Same as every node in this pack - ComfyUI Manager → search "opencv-comfyui", or clone https://github.com/geroldmeisinger/opencv-comfyui into custom_nodes, restart, and make sure OpenCV is installed (pip install opencv-contrib-python). You feed it NPARRAYs via Image2Nparray, batch size 1 only.

Two things that will bite you: the contour must be a single contour array, not a list of contours - if you wire a multi-contour result in, expect a shape error. And remember this node returns a scalar, not an image. It's control logic, not pixels, so don't try to route its output into Nparrays2Image. Think of it as a tiny sensor sitting inside your graph, telling you whether something is where you think it is.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
contourNPARRAY
ptSTRING
measureDistBOOLEAN

Outputs (1)

NameTypeDescription
floatFLOAT