python - 是否可以在Python中的drawcontour中为特定区域着色?

标签 python image-processing ocr opencv

我在 python 中从事图像处理工作,我使用 cv2.minAreaRect 检测补丁并绘制一个旋转的矩形,我实现了这一点。 enter image description here

现在我想将检测到的补丁完全填充为白色,这意味着cv2.drawContour内的青色区域完全填充为白色(期望的输出已在ms-paint中完成供引用)enter image description here 我想用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/

相关文章:

python - 通过迭代重命名Python嵌套字典中的键和子键

python - OCR的干净图像

java - Blackberry 的 OCR 库

ios - Tesseract OCR 无法识别除法符号 "÷"

python - 从 BeautifulSoup 返回的列表中提取唯一元素

python - 单个子图 Pyplot 上的多种绘图类型

c++ - 在多个数据 block 中搜索多个单词

matlab - Matlab 中的卷积实践

image-processing - 如何在SO上生成用户ID图像?

matlab - 在opencv中实现imclose(IM,SE)