From 1bff6b7333dbb2323052b396c4695cf00d389806 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Fri, 24 Jan 2025 11:47:27 +0800 Subject: [PATCH] Fix t_ocr.py for PNG image. (#4625) ### What problem does this PR solve? #4586 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- deepdoc/vision/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deepdoc/vision/__init__.py b/deepdoc/vision/__init__.py index c2c964326..64afcaf72 100644 --- a/deepdoc/vision/__init__.py +++ b/deepdoc/vision/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import io import pdfplumber @@ -48,7 +49,10 @@ def init_in_out(args): pdf_pages(fnm) return try: - images.append(Image.open(fnm)) + fp = open(fnm, 'rb') + binary = fp.read() + fp.close() + images.append(Image.open(io.BytesIO(binary)).convert('RGB')) outputs.append(os.path.split(fnm)[-1]) except Exception: traceback.print_exc()