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

update read image function #5053

Closed
wants to merge 2 commits into from

Conversation

WZMIAOMIAO
Copy link
Contributor

@WZMIAOMIAO WZMIAOMIAO commented Dec 24, 2021

在参加OCR十讲课程中,有使用到官方指定的数据集det_data_lesson_demo。在使用过程中发现,其中有很多是gif格式的图片(但后缀是.jpg),通过PaddleOCR官方的代码读取这些数据后全部为None(例如:mtwi/train/TB1Zj7Un4rI8KJjy0FpXXb5hVXa_!!1-item_pic.gif.jpg),还有些数据opencv会报Corrupt JPEG data看着很难受(例如:xfun/train/zh_train_43.jpg)。详情可以查看 #5092

PaddleOCR官方读取图片方式精简如下:

with open(img_path, 'rb') as f:
    img = f.read()
img = np.frombuffer(img, dtype='uint8')
img = cv2.imdecode(img, 1)

我将图片读取的方式修改成:

img = Image.open(img_path).convert('RGB')
img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)

通过我提供的方式读取gif图片时能够正常读取不会为None,并且也解决了opencv报Corrupt JPEG data警告的问题。

@paddle-bot-old
Copy link

Thanks for your contribution!

@littletomatodonkey
Copy link
Collaborator

您好,感谢反馈!这里是因为cv2的数据读取效率比PIL高一些,所以我们广泛使用了cv2的读图逻辑,这里不建议直接修改源码,您可以在自己的代码中添加PIL的数据读取~

@WZMIAOMIAO
Copy link
Contributor Author

好吧

@WZMIAOMIAO WZMIAOMIAO closed this Dec 25, 2021
@littletomatodonkey
Copy link
Collaborator

我们记录下,总结在FAQ中~

@littletomatodonkey
Copy link
Collaborator

littletomatodonkey commented Dec 25, 2021

#4982

您可以先在这里记录一下,作为特殊图像处理的解决办法哈

@WZMIAOMIAO
Copy link
Contributor Author

好滴

@WenmuZhou
Copy link
Collaborator

对于读取之后为None的图像,建议改为判断为None后使用Image读取

Corrupt JPEG data的问题不影响读取到的图片内容

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants