Monday, 15 February 2010

arrays - Removal of specific data from a list - Python -



arrays - Removal of specific data from a list - Python -

i have array of quadrilaterals, each item include 4 coordinates of square in image. example:

[ array([ [[599, 1]], [[173, 109]], [[202, 252]], [[445, 314]] ]), array([ [[1, 1]], [[1, 126]], [[57, 104]], [[48, 19]] ]) ]

i want programme find highest square in array.

i'm newbie in python, i'd glad clear reply :)

as noted in comments there multiple definitions of 'centroid' of quadrilateral. i'll assume vertex centroid - coordinates apparently arithmetic means of coordinates of 4 corners easy calculate.

quadrilaterals = [array([[599, 1]], [[173, 109]], [[202, 252]], [[445, 314]]), array([[1, 1]], [[1, 126]], [[57, 104]], [[48, 19]])] def centroid_y(polygon): homecoming polygon.mean(0)[1] # assuming numpy arrays

then maximum using centroid key.

print max(quadrilaterals, key=centroid_y)

python arrays

No comments:

Post a Comment