イメージファイルに白い背景と非白色のオブジェクトがあります。 python(ピロー)を使ってオブジェクトの中心を探したいと思います。Python - イメージ内のオブジェクトの中心を見つけよう
私はC言語で同様の質問を見られない++が、何の許容答えている - 私も、このページを読んで、それは私に与えるものではありませんWhat is the fastest way to find the center of an irregularly shaped polygon? (broken links in answer)
からHow can I find center of object?
編集: 私は、現在のソリューション - 便利なレシピhttps://en.wikipedia.org/wiki/Smallest-circle_problem
ここでは例の画像です使用してはこれです:
def find_center(image_file):
img = Image.open(image_file)
img_mtx = img.load()
top = bottom = 0
first_row = True
# First we find the top and bottom border of the object
for row in range(img.size[0]):
for col in range(img.size[1]):
if img_mtx[row, col][0:3] != (255, 255, 255):
bottom = row
if first_row:
top = row
first_row = False
middle_row = (top + bottom)/2 # Calculate the middle row of the object
left = right = 0
first_col = True
# Scan through the middle row and find the left and right border
for col in range(img.size[1]):
if img_mtx[middle_row, col][0:3] != (255, 255, 255):
left = col
if first_col:
right = col
first_col = False
middle_col = (left + right)/2 # Calculate the middle col of the object
return (middle_row, middle_col)
可能性のある重複した[見つけるための最速の方法は何ですか不規則な形のポリゴンの中心?](http://stackoverflow.com/questions/1203135/what-is-the-fastest-way-to-find-the-center-of-an-irularly-shaped-polygon) – user20160
@ user20160申し訳ありませんが、上記の答えがリンクを壊してしまったため、使用できないコード – Nir