Advertisement
Guest User

Untitled

a guest
Sep 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. # sudo apt update
  2. # sudo apt install -y poppler-utils
  3. # pip install pdf2image python-opencv
  4.  
  5. from pdf2image import convert_from_path
  6. import numpy as np
  7. import cv2
  8.  
  9. def image_np_bgr_to_rgb(image):
  10. """
  11. Converts the image into BGR2RGB
  12. :param image: Image as a list
  13. :return: numpy array as COLOR_BGR2RGB type
  14. """
  15.  
  16. return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  17.  
  18. def pdf_file_to_image_list(pdf_path: str):
  19. """
  20. Get a pdf from path and return a list of images, which represent each page of the input file
  21. :param pdf_path: PDF encoded in base64 str
  22. :return: List of bytes representing an image of each page of the input file
  23. """
  24. pages = convert_from_path(pdf_path)
  25. return [image_np_bgr_to_rgb(np.array(p)) for p in pages]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement