Skip to content

Commit f94dbab

Browse files
committed
Optimize PDF reader (#3677)
1 parent 962f62a commit f94dbab

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

paddlex/inference/utils/io/readers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ def __init__(self, rotate=0, zoom_x=2.0, zoom_y=2.0):
249249

250250
def read_file(self, in_path):
251251
for page in fitz.open(in_path):
252-
pix = page.get_pixmap(matrix=self.mat, alpha=False)
253-
getpngdata = pix.tobytes(output="png")
254-
# decode as np.uint8
255-
image_array = np.frombuffer(getpngdata, dtype=np.uint8)
256-
img_cv = cv2.imdecode(image_array, cv2.IMREAD_ANYCOLOR)
252+
pixmap = page.get_pixmap(matrix=self.mat, alpha=False)
253+
img_cv = np.frombuffer(pixmap.samples, dtype=np.uint8).reshape(
254+
pixmap.h, pixmap.w, pixmap.n
255+
)
256+
img_cv = cv2.cvtColor(img_cv, cv2.COLOR_RGB2BGR)
257257
yield img_cv
258258

259259

0 commit comments

Comments
 (0)