Skip to content

correct_rotation

Return the input image in the coordinate frame of an analysis result.

When rotation correction (enable_preprocess=True) is applied, all coordinates in the result refer to the orientation-corrected image. Pass the original input image together with its result to get the image that matches those coordinates, e.g. before create_searchable_pdf() or figure export. If no rotation was applied, the image is returned as is.

引数:

名前 タイプ デスクリプション デフォルト
img ndarray

The original input image passed to the analyzer.

必須
result

An analysis result with a preprocess field (DocumentAnalyzerSchema, OCRSchema, TableSemanticParserSchema).

必須

戻り値:

タイプ デスクリプション

np.ndarray: The image whose orientation matches the result coordinates.

ソースコード位置: src/yomitoku/utils/rotation.py
def correct_rotation(img, result):
    """
    Return the input image in the coordinate frame of an analysis result.

    When rotation correction (``enable_preprocess=True``) is applied, all
    coordinates in the result refer to the orientation-corrected image. Pass
    the original input image together with its result to get the image that
    matches those coordinates, e.g. before ``create_searchable_pdf()`` or
    figure export. If no rotation was applied, the image is returned as is.

    Args:
        img (np.ndarray): The original input image passed to the analyzer.
        result: An analysis result with a ``preprocess`` field
            (DocumentAnalyzerSchema, OCRSchema, TableSemanticParserSchema).

    Returns:
        np.ndarray: The image whose orientation matches the result coordinates.
    """
    preprocess = getattr(result, "preprocess", None)
    if preprocess is None:
        return img
    return rotate_by_angle(img, preprocess.angle)