Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Transparent images with white fonts are not handled correctly. #158

Closed
SWHL opened this issue Mar 6, 2024 · 2 comments
Closed

[Bug] Transparent images with white fonts are not handled correctly. #158

SWHL opened this issue Mar 6, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@SWHL
Copy link
Collaborator

SWHL commented Mar 6, 2024

请提供下述完整信息以便快速定位问题
(Please provide the following information to quickly locate the problem)

  • 系统环境/System Environment: macOS

  • 使用的是哪门语言的程序/Which programing language: Python

  • 所使用语言相关版本信息/Version: 3.10.13

  • OnnxRuntime版本/OnnxRuntime Version: 1.17.0

  • 使用当前库的版本/Use version: rapidocr_onnxruntime==1.3.14

  • 可复现问题的demo和文件/Demo of reproducible problems:

    import cv2
    import numpy as np
    
    
    def cvt_four_to_three(img: np.ndarray) -> np.ndarray:
        """RGBA → BGR"""
        r, g, b, a = cv2.split(img)
        new_img = cv2.merge((b, g, r))
    
        not_a = cv2.bitwise_not(a)
        not_a = cv2.cvtColor(not_a, cv2.COLOR_GRAY2BGR)
    
        new_img = cv2.bitwise_and(new_img, new_img, mask=a)
        new_img = cv2.add(new_img, not_a)
        return new_img
    
    
    img_path = "1.png"
    img = cv2.imread(img_path, cv2.IMREAD_UNCHANGED)
    res_img = cvt_four_to_three(img)
    
    cv2.imwrite("res.png", res_img)
    print("ok")
  • 所用图像/ Use image:
    1.png.zip

  • 程序执行结果(注意下面有一张图,只不过是全白的):
    (Result (note that there is an image below, but it is completely white))
    res

@SWHL SWHL self-assigned this Mar 6, 2024
@SWHL SWHL added the bug Something isn't working label Mar 6, 2024
@SWHL
Copy link
Collaborator Author

SWHL commented Mar 6, 2024

Maybe a solution:

def cvt_four_to_three(img: np.ndarray) -> np.ndarray:
    """RGBA → BGR"""
    r, g, b, a = cv2.split(img)
    new_img = cv2.merge((b, g, r))

    not_a = cv2.bitwise_not(a)
    not_a = cv2.cvtColor(not_a, cv2.COLOR_GRAY2BGR)

    new_img = cv2.bitwise_and(new_img, new_img, mask=a)

    mean_color = np.mean(new_img)
    if mean_color <= 0.0:
        new_img = cv2.add(new_img, not_a)
    else:
        new_img = cv2.bitwise_not(new_img)
    return new_img

SWHL added a commit that referenced this issue Mar 7, 2024
@SWHL
Copy link
Collaborator Author

SWHL commented Mar 7, 2024

The issue has been fixed in rapidocr_onnxruntime>=1.3.15, rapidocr_openvino>=1.3.15 and rapidocr_paddle>=1.3.17.

@SWHL SWHL closed this as completed Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant