-
-
Save clairesg/25ec48c481e4526a3ca8aec0adc48588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fitz | |
import pytesseract | |
def convert_to_img(pdf): | |
doc = fitz.open(pdf) | |
page = doc.loadPage(0) | |
pix = page.getPixmap() | |
output = f"{pdf.split(".")[0]}.png" | |
pix.writePNG(output) | |
def convert_to_string(image) | |
img_cv = cv2.imread(image) | |
img_rgb = cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB) | |
print(pytesseract.image_to_string(img_rgb)) | |
if __name__ == '__main__': | |
convert_to_img('text.pdf') | |
convert_to_string('text.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment