OpenCV nearest neighbour instancing

Hi,

I have written a python script TOP which fills a table DAT with the start and end points of lines x1,y1,x2,y2. I am trying to render the connecting lines as geometry using DBraun’s numpy distance pairs tox. I’ve gotten as far as joining the x channels together and joining the y channels together then merging them and passing them to the script CHOP. This seems very close to what I’m intending to do, however its joining all of the points together and drawing connections between every point instead of drawing the connections between the localised groups of points nearest to each other.

I’ve already been through Matthew Ragan’s object CHOP techniques and thought that might be the way however, I got stuck when it came to instancing connections between a constantly changing number of instances.

See below for the example of my low res numpy output which I am trying to recreate through geometry.

Any help on this would be amazing!!

Cheers
J