在 OpenCV 中处理带有文本的图像时,我的打开操作不会产生正确的输出数据。该问题与本文中描述的问题非常相似:http://www.cpe.eng.cmu.ac.th/wp-content/uploads/CPE752_06part2.pdf
据我所见,人们建议使用重建操作。OpenCV 或一些已知的库/代码中是否有任何内置机制可以实现这一点?
Here's my Python3执行 in 与 MatLab 的类比imreconstruct
算法:
import cv2
import numpy as np
def imreconstruct(marker: np.ndarray, mask: np.ndarray, radius: int = 1):
"""Iteratively expand the markers white keeping them limited by the mask during each iteration.
:param marker: Grayscale image where initial seed is white on black background.
:param mask: Grayscale mask where the valid area is white on black background.
:param radius Can be increased to improve expansion speed while causing decreased isolation from nearby areas.
:returns A copy of the last expansion.
Written By Semnodime.
"""
kernel = np.ones(shape=(radius * 2 + 1,) * 2, dtype=np.uint8)
while True:
expanded = cv2.dilate(src=marker, kernel=kernel)
cv2.bitwise_and(src1=expanded, src2=mask, dst=expanded)
# Termination criterion: Expansion didn't change the image at all
if (marker == expanded).all():
return expanded
marker = expanded
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)