[SOLVED] How to get line by line (for python) in google vision text detection?

Issue

This Content is from Stack Overflow. Question asked by Rafi Abrar

Medical Test Report

I get outputs like this:
White Blood Cells
Neutrophil
Lymphocyte
Monocyte
Result
8.25 K/µL
4.29 K/μL
3.55 K/µL
0.25

But instead, I want to output line by line, like:
White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL



Solution

You should parse the output, separating the labels and results into two separate lists, and then merge them together.

input_str = """White Blood Cells
Neutrophil
Lymphocyte
Monocyte
Result
8.25 K/µL
4.29 K/μL
3.55 K/µL
0.25"""

input_split = input_str.split('\n')

label_list = []
result_list = []
read_result = False

for line in input_split:
    if line == "Result":
        read_result = True
        continue

    if read_result:
        result_list.append(line)
    
    else:
        label_list.append(line)

for (result, label) in zip(label_list, result_list):
    print(result, label)

Output:

White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL
Monocyte 0.25


This Question was asked in StackOverflow by Rafi Abrar and Answered by JRose It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?