python中imag是什么意思_Python-在imag中查找对象的中心
我有一個圖像文件,它有一個非白色對象的白色背景。
我想用python(枕頭)找到物體的中心。
下面是一個示例圖像:
編輯:
我目前使用的解決方案是: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)
總結
以上是生活随笔為你收集整理的python中imag是什么意思_Python-在imag中查找对象的中心的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: echartsdemo可视化统计(笔记分
- 下一篇: 程序员进阶架构师、技术总监、CTO,需要