Skip to content

Instantly share code, notes, and snippets.

@sleepless-se
Created February 27, 2019 00:52
Show Gist options
  • Save sleepless-se/d1cde771cf3af072e29f31e0633a6cb3 to your computer and use it in GitHub Desktop.
Save sleepless-se/d1cde771cf3af072e29f31e0633a6cb3 to your computer and use it in GitHub Desktop.
Get object's center
def get_object_center(rois,image):
height = image.shape[0]
width = image.shape[1]
center = width / 2
print(width,height)
print('center',center)
max_area = 0
for i in range(len(rois)):
print(rois[i])
start_height = rois[i][0]
start_width = rois[i][1]
end_height = rois[i][2]
end_width = rois[i][3]
height = end_height - start_height
width = end_height - start_height
area = height * width
if area < max_area:continue
max_area = area
center = start_width + width / 2
print('update center',center)
return center
get_object_center(r['rois'],image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment