4

OpenCV でテキストを含む画像を処理する場合、開く操作で適切な出力データが得られません。この問題は、この記事で説明されている問題と非常によく似ています: http://www.cpe.eng.cmu.ac.th/wp-content/uploads/CPE752_06part2.pdf

PDF セクションのスクリーンショット

私が見る限り、人々は再構築操作を使用することを提案しています。OpenCVまたはこれを実装する既知のライブラリ/コードに組み込みメカニズムはありますか?

4

2 に答える 2

5

以下は、MatLab のアルゴリズム類似した私のPython3実装です。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 に答える