cv2.HoughLinesPointSet
Fit a line through a pile of points, not a picture
- point
- nparray
Every other Hough node in this pack takes an image. This one takes a point set - a list of (x, y) coordinates - and tells you which lines those points lie on, with a vote count per line. No edges, no Canny, no raster at all.
That makes it the natural follow-up to a corner or keypoint detector. You have 400 feature points; you suspect a subset of them lie on a single straight structure (a lane marking, a horizon, a ruler edge); a least-squares fit through all 400 would be nonsense because 350 of them belong to something else. Hough over the point set is the classic robust answer: vote, then read the peaks. It is a poor man's RANSAC with a fixed voting grid, and it is deterministic and fast.
It is also your bridge between the point-typed and image-typed halves of the pack. The input here is not an image socket at all - the schema marks it as a data array, so only an NPARRAY link is accepted.
How it works
Given the points, it builds a (rho, theta) accumulator exactly like the classic transform, but the only contributors are your points. You must supply the search window explicitly: min_rho and max_rho bound the distance from the origin (top-left pixel, so rho can go negative - the tooltip notes |rho| is the distance to the origin, and the sign carries the side), and min_theta / max_theta bound the angle. rho_step and theta_step are the resolutions of that grid, and threshold is how many points must agree before a line is returned.
That explicit window is both the feature and the annoyance: there is no sensible default for a general coordinate system, so you have to think about your point cloud's extent before you get anything out. And since all nine parameters are required, there is no "blank means OpenCV default" escape.
Inputs
point- the point set. Type must be a 32-bit float or 32-bit signed integer two-channel array, which is exactly what a corner detector's output is.cv2.goodFeaturesToTrackoutput plugs in directly, as does anything fromCV Points,CV Grid Points,cv2.findNonZero, orCV Contour To Points.lines_max- cap on returned lines. Set it low (5–20); you want peaks, not the whole accumulator.threshold- minimum votes. With 300 points, 30–80 is a reasonable starting range.min_rho,max_rho- the distance search window. Cover the diagonal of your image in both directions if you are not sure - remember negative rho means the line passes on the other side of the origin.rho_step- distance resolution. 1 pixel is the usual choice.min_theta,max_theta- angle window in radians. Restricting this is the single biggest speed and precision win: if you are only looking for near-horizontal lines, do not search the full 180°.theta_step- angle resolution in radians, e.g.0.01745for one degree.
Output is a single nparray of (votes, rho, theta) rows, strongest first.
Wiring it up
The output is polar, same as cv2.HoughLines, so it is data rather than a drawing. Useful moves: CV Array To Text to read the angles, cv2.sortIdx on the vote column, CV Take By Index for the top line, and the pack's angle/rotation nodes to turn a measured theta into a deskew. If you want to see the rest, overlay the points with CV Draw Points and trust the numbers for the line itself.
The pack ships 07_hough_playground.json, aimed at the image-based variants but still the fastest way to build intuition for how a threshold moves the accumulator. If your actual goal is "find line segments in this picture", cv2.HoughLinesP or the curated CV Detect Lines (Hough) gets you there in one node; come back here when your input is points.
Install
Manager → search comfyui_cv (bmad4ever), or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Python ≥ 3.12 and a recent ComfyUI on the V3 API. No models, no downloads, and that pinned wheel is the whole dependency list.
When it goes wrong
- Empty output, always. Almost always the search window: if
min_rho/max_rhodo not cover where your lines actually are, nothing can be found, and ifrho_steportheta_stepis 0 the grid does not exist. Check the extent of your points withCV Array Statisticfirst. - The same line reported repeatedly. Steps too fine relative to
lines_max: neighbouring accumulator cells hold the same peak. Coarsentheta_stepor raise the threshold. - A single very tall accumulator line. Theta resolution too coarse, so vertical lines and lines a degree off collapse together.
- You wired an image in. The schema says data array, and cv2 will reject a 3-D array here. Convert first with
CV Contour To Points, or use the corner detector's output. - Zero
lines_max/threshold. Both are required integers whose widgets start at 0, and 0 means "no lines" / "one vote". Type real values.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| point | NPARRAY | Input vector of points. Each vector must be encoded as a Point vector $(x,y)$. Type must be CV_32FC2 or CV_32SC2. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here. | |
| lines_max | INT | 0-2147483648–2147483647 | Max count of Hough lines. |
| threshold | INT | 0-2147483648–2147483647 | %Accumulator threshold parameter. Only those lines are returned that get enough votes ( $>\texttt{threshold}$ ). |
| min_rho | FLOAT | 0.0000-1e+38–1e+38 | Minimum value for $\rho$ for the accumulator (Note: $\rho$ can be negative. The absolute value $|\rho|$ is the distance of a line to the origin.). |
| max_rho | FLOAT | 0.0000-1e+38–1e+38 | Maximum value for $\rho$ for the accumulator. |
| rho_step | FLOAT | 0.0000-1e+38–1e+38 | Distance resolution of the accumulator. |
| min_theta | FLOAT | 0.0000-1e+38–1e+38 | Minimum angle value of the accumulator in radians. |
| max_theta | FLOAT | 0.0000-1e+38–1e+38 | Upper bound for the angle value of the accumulator in radians. The actual maximum angle may be slightly less than max_theta, depending on the parameters min_theta and theta_step. |
| theta_step | FLOAT | 0.0000-1e+38–1e+38 | Angle resolution of the accumulator in radians. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |