Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to issue #94 #95

Merged
merged 2 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/layoutparser/ocr/tesseract_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

if is_pytesseract_available():
import pytesseract
from pytesseract import Output


class TesseractFeatureType(BaseOCRElementType):
Expand Down Expand Up @@ -89,10 +90,13 @@ def _detect(self, img_content):
res["text"] = pytesseract.image_to_string(
img_content, lang=self.lang, **self.configs
)
_data = pytesseract.image_to_data(img_content, lang=self.lang, **self.configs)
res["data"] = pd.read_csv(
io.StringIO(_data), quoting=csv.QUOTE_NONE, encoding="utf-8", sep="\t"
)
_data = pytesseract.image_to_data(img_content, lang=self.lang, output_type=Output.DICT, **self.configs)
_df = pd.DataFrame(_data, dtype=str)
_cols = list(_df.columns())
_cols.remove('text')
for col in _cols:
_df[col] = _df[col].astype(int)
res['data'] = _df
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try the following code:

_data = pytesseract.image_to_data(img_content, lang=self.lang, **self.configs)
df = pd.read_csv(
   io.StringIO(_data), quoting=csv.QUOTE_NONE, encoding="utf-8", sep="\t"
)
df['text'] = df['text'].astype('str')
res["data"] = df

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lolipopshock sorry it does not, I have tried this
and ya i get it, the for loop and all that stuff looks ugly :)

here's the screenshot
layout_parse

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see -- it's the issue from floating point numbers .0 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

return res

def detect(
Expand Down