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

最新opencv cv2.imdecode返回的是RGB,不是BGR,operators.py里的DecodeImage多转了一次 #14480

Closed
3 tasks done
zzk2021 opened this issue Jan 2, 2025 · 4 comments
Closed
3 tasks done
Labels
bug Something isn't working status/close

Comments

@zzk2021
Copy link

zzk2021 commented Jan 2, 2025

🔎 Search before asking

  • I have searched the PaddleOCR Docs and found no similar bug report.
  • I have searched the PaddleOCR Issues and found no similar bug report.
  • I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

导致推理结果不一致

🏃‍♂️ Environment (运行环境)

windows10

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

原图
image

通道逆置后之后就这样了
image

@zzk2021
Copy link
Author

zzk2021 commented Jan 2, 2025

class DecodeImage(object):
"""decode image"""

def __init__(
    self, img_mode="RGB", channel_first=False, ignore_orientation=False, new_load=True,**kwargs
):
    self.img_mode = img_mode
    self.channel_first = channel_first
    self.ignore_orientation = ignore_orientation
    self.new_load = new_load
def __call__(self, data):
    img = data["image"]
    if self.new_load:
        np_arr = np.frombuffer(img, dtype=np.uint8)
        img = cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED)
        data["image"] = img
        return data
    
    if six.PY2:
        assert (
            type(img) is str and len(img) > 0
        ), "invalid input 'img' in DecodeImage"
    else:
        assert (
            type(img) is bytes and len(img) > 0
        ), "invalid input 'img' in DecodeImage"
    img = np.frombuffer(img, dtype="uint8")
    if self.ignore_orientation:
        img = cv2.imdecode(img, cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR)
    else:
        img = cv2.imdecode(img, 1)
    if img is None:
        return None
    if self.img_mode == "GRAY":
        img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
    elif self.img_mode == "RGB":
        assert img.shape[2] == 3, "invalid shape of image[%s]" % (img.shape)
        img = img[:, :, ::-1]

    if self.channel_first:
        img = img.transpose((2, 0, 1))

    data["image"] = img
    return data

new_load是我加的,只有走new_load才是正常的

@jingsongliujing
Copy link
Collaborator

你好,能否提个pr修复此问题

@jingsongliujing jingsongliujing added the bug Something isn't working label Jan 2, 2025
@GreatV
Copy link
Collaborator

GreatV commented Jan 3, 2025

@zzk2021
Copy link
Author

zzk2021 commented Jan 3, 2025

https://docs.opencv.org/4.10.0/d4/da8/group__imgcodecs.html#gaad518fe65098fd32446bd5b9c4f8b531 OpenCV文档里写的写BGR

那可能是我搞错了,cv2.imshow输入时BGR的。但是我们测试过程中,走这个DecodeImage以及paddleocr和不走DecodeImage直接调用paddleocr结果不一样,我们检查了分辨率等因素,最后确定是DecodeImage的问题。可能是其他地方没转

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status/close
Projects
None yet
Development

No branches or pull requests

3 participants