Explorar el Código

Optimize PDF reader (#3677)

Lin Manhui hace 8 meses
padre
commit
5ede665321
Se han modificado 1 ficheros con 5 adiciones y 5 borrados
  1. 5 5
      paddlex/inference/utils/io/readers.py

+ 5 - 5
paddlex/inference/utils/io/readers.py

@@ -249,11 +249,11 @@ class PDFReaderBackend(_BaseReaderBackend):
 
     def read_file(self, in_path):
         for page in fitz.open(in_path):
-            pix = page.get_pixmap(matrix=self.mat, alpha=False)
-            getpngdata = pix.tobytes(output="png")
-            # decode as np.uint8
-            image_array = np.frombuffer(getpngdata, dtype=np.uint8)
-            img_cv = cv2.imdecode(image_array, cv2.IMREAD_ANYCOLOR)
+            pixmap = page.get_pixmap(matrix=self.mat, alpha=False)
+            img_cv = np.frombuffer(pixmap.samples, dtype=np.uint8).reshape(
+                pixmap.h, pixmap.w, pixmap.n
+            )
+            img_cv = cv2.cvtColor(img_cv, cv2.COLOR_RGB2BGR)
             yield img_cv