Youssouf Traore commited on
Commit
94affbe
·
1 Parent(s): 84772c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,15 +1,17 @@
1
  import gradio as gr
2
  import pytesseract
3
  from PIL import Image
4
-
5
  def extract_text(image):
6
- # Convertir l'image en noir et blanc pour une meilleure extraction de texte
7
- image = image.convert('L')
8
-
9
- # Utiliser Pytesseract pour extraire le texte de l'image
10
- text = pytesseract.image_to_string(image)
11
- print(text)
12
- return text
 
 
13
 
14
  # Définir l'interface utilisateur Gradio
15
  inputs = gr.inputs.Image()
 
1
  import gradio as gr
2
  import pytesseract
3
  from PIL import Image
4
+ import cv2
5
  def extract_text(image):
6
+
7
+ img_cv = cv2.imread(image)
8
+ # By default OpenCV stores images in BGR format and since pytesseract assumes RGB format,
9
+ # we need to convert from BGR to RGB format/mode:
10
+ img_rgb = cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB)
11
+ print(pytesseract.image_to_string(img_rgb))
12
+ # OR
13
+ img_rgb = Image.frombytes('RGB', img_cv.shape[:2], img_cv, 'raw', 'BGR', 0, 0)
14
+ print(pytesseract.image_to_string(img_rgb))
15
 
16
  # Définir l'interface utilisateur Gradio
17
  inputs = gr.inputs.Image()