This is the code I used:
from http import client
import os, io
from google.cloud import vision
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()
def detectText(img):
with io.open(img,'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
texts = response.text_annotations[0].description
print(texts)
FILE_NAME = 'Scan_20220819.png'
FOLDER_NAME = r'C:\Users\RafiAbrar\Downloads\vision ai'
detectText(os.path.join(FOLDER_NAME, FILE_NAME))
The output is:
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
Haemoglobin
ESR (Capillary Method - Alifax)
Total Count
Red Blood Cells
Platelets
White Blood Cells
Differential Count
Neutrophil
Lymphocyte
Monocyte
Eosinophil
Basophil
Red Cell Indices
P.C.V. (Hct)
M.C.V.
M.C.H.
M.C.H.C.
R.D.W.-C.V.
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
Result
11.5 g/dL
12 mm in 1st hour
3.7 X 10^12/L
257 X 10^9/L
8.0 X 10^9/L
62%
32 %
04%
02 %
00%
33%
88 fL
31 pg
35 g/dL
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
12.3%
+
Reference Value
F 11.5 - 15.5, M 13.5 - 18.0 g/dL
< 30 mm in 1st hour
F 3.8-4.8, M 4.5-5.5 X 0^12/L
150-450 X 10^9/L
04.00 11.00 X 10^9/L
40 - 75%
20 - 50 %
02-10%
01-06 %
<01 %
F: 36-46 %, M: 40 - 50 %
82 - 100 fl
27-32 pg
30-35 g/dL
11.60 14.00 %
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
A lot of extra stuffs
The text is not detected as line by line.
I'm expecting out put like: "parameter" (space) "value" (space) "unit"
Like:
Haemoglobin 11.5 g/dL
ESR 12 mm in 1st hour
RBC 3.7 X 10^12/L
..... and the list goes on
So what I'm asking is:
- Either help me with a way where I can ocr text line by line using python
- or help me find an appropriate LOGIC (slicing/loop/parsing/anything) for the given output where I can merge every specific test report parameter with its corresponding value.