merve HF staff nlztrk commited on
Commit
7915a28
1 Parent(s): 934c95a

Added gray-scale and negative preprocessing for input images (#3)

Browse files

- Added gray-scale and negative preprocessing for input images (526878502041b8b920a56469195bd790e9c36405)


Co-authored-by: Anil Ozturk <nlztrk@users.noreply.huggingface.co>

Files changed (2) hide show
  1. app.py +16 -3
  2. requirements.txt +3 -1
app.py CHANGED
@@ -8,19 +8,32 @@ import openai
8
  import ast
9
  import os
10
  from deta import Deta
 
11
 
12
 
13
  openai.api_key = os.getenv('API_KEY')
14
  reader = Reader(["tr"])
15
 
 
16
  def get_parsed_address(input_img):
17
 
18
  address_full_text = get_text(input_img)
19
  return openai_response(address_full_text)
20
-
21
 
22
- def get_text(input_img):
23
- result = reader.readtext(input_img, detail=0)
 
 
 
 
 
 
 
 
 
 
 
 
24
  return " ".join(result)
25
 
26
 
 
8
  import ast
9
  import os
10
  from deta import Deta
11
+ import cv2
12
 
13
 
14
  openai.api_key = os.getenv('API_KEY')
15
  reader = Reader(["tr"])
16
 
17
+
18
  def get_parsed_address(input_img):
19
 
20
  address_full_text = get_text(input_img)
21
  return openai_response(address_full_text)
 
22
 
23
+
24
+ def preprocess_img(inp_image):
25
+ gray = cv2.cvtColor(inp_image, cv2.COLOR_BGR2GRAY)
26
+ gray_img = cv2.bitwise_not(gray)
27
+ return gray_img
28
+
29
+
30
+ def get_text(image):
31
+ processed_image = preprocess_img(inp_image=image)
32
+ result = reader.readtext(processed_image,
33
+ detail=0,
34
+ paragraph=True
35
+ )
36
+
37
  return " ".join(result)
38
 
39
 
requirements.txt CHANGED
@@ -2,4 +2,6 @@ openai
2
  Pillow
3
  easyocr
4
  gradio
5
- deta
 
 
 
2
  Pillow
3
  easyocr
4
  gradio
5
+ deta
6
+ opencv-python
7
+ opencv-contrib-python