Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sudo apt update
- # sudo apt install -y poppler-utils
- # pip install pdf2image python-opencv
- from pdf2image import convert_from_path
- import numpy as np
- import cv2
- def image_np_bgr_to_rgb(image):
- """
- Converts the image into BGR2RGB
- :param image: Image as a list
- :return: numpy array as COLOR_BGR2RGB type
- """
- return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- def pdf_file_to_image_list(pdf_path: str):
- """
- Get a pdf from path and return a list of images, which represent each page of the input file
- :param pdf_path: PDF encoded in base64 str
- :return: List of bytes representing an image of each page of the input file
- """
- pages = convert_from_path(pdf_path)
- return [image_np_bgr_to_rgb(np.array(p)) for p in pages]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement