在找到中心之前尝试填充广场。我通过迭代行并连接最左边和最右边的黑色像素来做到这一点。
# Iterate through each row in the image
for row in range(img.shape[0]):
# Find the left-most and right-most pixel in the sqare
start, stop = 0, 0
for col in range(img.shape[1]):
# Find the left-most
if img[row,col] != 255 and start == 0: start = col, row
# Find the right-most
if img[row,col] != 255: stop = col, row
# If there was a pixel in that row, connect them with a line
if start != 0:
cv2.line(img, start, stop, 0, 1)
</code>