Youssouf Traore commited on
Commit
6353308
·
1 Parent(s): 14b4a59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,17 +1,19 @@
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()
 
1
  import gradio as gr
2
  import pytesseract
 
3
  import cv2
4
+ from PIL import Image
5
 
6
+ def extract_text(image):
7
+ # Convertir le tableau numpy.ndarray en objet Image de la bibliothèque PIL
8
+ image = Image.fromarray(image)
9
+
10
+ # Convertir l'image en noir et blanc pour une meilleure extraction de texte
11
+ image = image.convert('L')
12
+
13
+ # Utiliser Pytesseract pour extraire le texte de l'image
14
+ text = pytesseract.image_to_string(image)
15
+
16
+ return text
17
 
18
  # Définir l'interface utilisateur Gradio
19
  inputs = gr.inputs.Image()