灰度
import cv2
import numpy as np
import matplotlib.pyplot as plt
h = 50
x_center = 70
y_center = 120
img = np.zeros([256,256],'uint8')
draw_0 = cv2.rectangle(img, (x_center-h, y_center-h), (x_center+h, y_center+h), 1, 2)
plt.figure()
plt.imshow(draw_0)
mask = np.zeros([258, 258],np.uint8)
cv2.floodFill(draw_0, mask, (58, 117), 1, cv2.FLOODFILL_FIXED_RANGE)
plt.figure()
plt.imshow(draw_0)
彩色
img = np.zeros([256,256,3],'uint8')
draw_0 = cv2.rectangle(img, (x_center-h, y_center-h), (x_center+h, y_center+h), (255, 0, 0), 2)
cv2.imshow('a',draw_0)
mask = np.zeros([258, 258],np.uint8)
cv2.floodFill(draw_0, mask, (58, 117), (0, 255, 255), cv2.FLOODFILL_FIXED_RANGE)
cv2.imshow('b',draw_0)