我在 python 中从事图像处理工作,我使用 cv2.minAreaRect 检测补丁并绘制一个旋转的矩形,我实现了这一点。
现在我想将检测到的补丁完全填充为白色,这意味着cv2.drawContour
内的青色区域完全填充为白色(期望的输出已在ms-paint中完成供引用)
我想用python实现,在OpenCV-python中可以吗?
最佳答案
假设您已将轮廓保存在 cnts
中。然后以下代码片段将用青色填充旋转的矩形。
import numpy as np
import cv2
for c in cnts:
rotrect = cv2.minAreaRect(c)
box = cv2.boxPoints(rotrect)
box = np.int0(box)
cv2.drawContours(image, [box], 0, (255, 255, 0), -1) # as opencv stores in BGR format
关于python - 是否可以在Python中的drawcontour中为特定区域着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62485669/