Sort contours in python
How can we sort contours from left to right and top to bottom in python
How can we sort contours from left to right and top to bottom in python
It is explained with code in the middle part of this SOF: http://stackoverflow.com/a/11366549/1134940
Below is the extracted part of that answer:
resulting centroids won't be sorted. Check out below image to see their order:
So we sort them from left to right, top to bottom.
centroids = np.array(centroids,dtype = np.float32)
c = centroids.reshape((100,2))
c2 = c[np.argsort(c[:,1])]
b = np.vstack([c2[i*10:(i+1)*10][np.argsort(c2[i*10:(i+1)*10,0])] for i in xrange(10)])
bm = b.reshape((10,10,2))
Now see below their order :
Asked: 2014-06-04 11:49:50 -0600
Seen: 4,135 times
Last updated: Jun 04 '14