Skip to content
Discussion options

You must be logged in to vote

已经解决了。我后来又仔细的看了一遍源码。发现 load_image.py 文件中 类 LoadImage 在后续的提交中,主动去除掉了 __call__ 函数中对这里的调用:

if img.ndim == 3:
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

所以导致PNG图像加载后, RGBA -> BGR 缺失了白底。正好我也在使用 RapidOCR,RapidUndistorted,仔细都看了一下发现每个库的 load_image 文件 实现细节都不一样。我为了统一使用同一个文件夹加载器,并且避免已经加载过的 ndarray 在流转的时候反复的去做额外的判断,就继承了 LoadImage 类,重写了 convert_img 方法,把 cv2.cvtColor(img, cv2.COLOR_RGB2BGR) 的逻辑补充回去了。

def convert_img(self, img: np.ndarray, origin_img_type: Any) -> np.ndarray:
    if img.ndim == 2:
        return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
    elif img.ndim == 3 and (channel := img.shape[2]):
        if channel == 1:
            return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
        elif cha…

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@SWHL
Comment options

SWHL Oct 23, 2025
Maintainer

@miss85246
Comment options

@SWHL
Comment options

SWHL Oct 23, 2025
Maintainer

@miss85246
Comment options

@SWHL
Comment options

SWHL Oct 23, 2025
Maintainer

Comment options

You must be logged in to vote
3 replies
@miss85246
Comment options

Answer selected by miss85246
@SWHL
Comment options

SWHL Feb 12, 2026
Maintainer

@miss85246
Comment options

Comment options

You must be logged in to vote
1 reply
@miss85246
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #43 on October 23, 2025 01:15.