4

在 OpenCV 中处理带有文本的图像时,我的打开操作不会产生正确的输出数据。该问题与本文中描述的问题非常相似: http ://www.cpe.eng.cmu.ac.th/wp-content/uploads/CPE752_06part2.pdf

PDF部分的截图

我所看到的,人们建议使用重建操作。OpenCV 中是否有任何内置机制或一些已知的库/代码可以实现这一点?

4

2 回答 2

5

这是我的Python3实现类似于 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
于 2020-06-29T16:34:01.667 回答
2

这个答案来晚了,但这是重建不足的基本算法:

  1. 输入是两个图像:ImReference 和 ImMarker,标记 <= 参考
  2. 中间图像:ImRec
  3. 输出图像:ImResult
  4. 将 ImMarker 复制到 ImRec
  5. 将 ImRec 复制到 ImResult
  6. ImDilated = 膨胀(ImResult)
  7. ImRec = 最小值(ImDilated,ImReference)
  8. 如果 ImRec != ImResult 则返回步骤 5。

它不是最优化的算法,但它只使用基本操作。

于 2015-12-30T22:47:14.563 回答