SelimGilon commited on
Commit
c8e9cdf
·
1 Parent(s): 5fd0ec4
Files changed (2) hide show
  1. app.py +19 -13
  2. packages.txt +2 -1
app.py CHANGED
@@ -2,7 +2,8 @@ import io
2
  import urllib
3
  import pandas as pd
4
  import numpy as np
5
- import fitz
 
6
  import cv2
7
  import pytesseract
8
  import requests
@@ -165,19 +166,24 @@ shops = {
165
  # Add more shops and their respective information here
166
  }
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  def pdf_to_images(pdf_path):
169
- doc = fitz.open(pdf_path)
170
- images = []
171
- for page in doc:
172
- for img in page.get_images(full=True):
173
- xref = img[0]
174
- base_image = doc.extract_image(xref)
175
- image_bytes = base_image["image"]
176
- # You can use PIL to do many things with this image data.
177
- # If you need it as an array for OpenCV, you can do that as follows:
178
- image = Image.open(io.BytesIO(image_bytes))
179
- images.append(np.array(image))
180
- return images
181
 
182
 
183
  def get_yolo_predictions(image):
 
2
  import urllib
3
  import pandas as pd
4
  import numpy as np
5
+ # import fitz
6
+ from pdf2image import convert_from_path
7
  import cv2
8
  import pytesseract
9
  import requests
 
166
  # Add more shops and their respective information here
167
  }
168
 
169
+ # def pdf_to_images(pdf_path):
170
+ # doc = fitz.open(pdf_path)
171
+ # images = []
172
+ # for page in doc:
173
+ # for img in page.get_images(full=True):
174
+ # xref = img[0]
175
+ # base_image = doc.extract_image(xref)
176
+ # image_bytes = base_image["image"]
177
+ # # You can use PIL to do many things with this image data.
178
+ # # If you need it as an array for OpenCV, you can do that as follows:
179
+ # image = Image.open(io.BytesIO(image_bytes))
180
+ # images.append(np.array(image))
181
+ # return images
182
+
183
  def pdf_to_images(pdf_path):
184
+ images = convert_from_path(pdf_path)
185
+ return [cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) for img in images]
186
+
 
 
 
 
 
 
 
 
 
187
 
188
 
189
  def get_yolo_predictions(image):
packages.txt CHANGED
@@ -1 +1,2 @@
1
- tesseract-ocr-all
 
 
1
+ tesseract-ocr-all
2
+ poppler