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

Finding position of block is so slow #138

Closed
azs-rahimi opened this issue Nov 25, 2014 · 15 comments
Closed

Finding position of block is so slow #138

azs-rahimi opened this issue Nov 25, 2014 · 15 comments
Labels

Comments

@azs-rahimi
Copy link

Hi
I need to find position of each text block in image. I've read issue #64 and #81 and according to those, my code is:

Tesseract.Pix pix = Tesseract.PixConverter.ToPix(testimg);
using (var page = engine.Process(pix))
{
using (var iter = page.GetIterator())
{
do
{
if (iter.TryGetBoundingBox(Tesseract.PageIteratorLevel.Block, out blockBounds))
{
imgblock.Draw(new Rectangle(blockBounds.X1, blockBounds.Y1, blockBounds.Width, blockBounds.Height), new Bgr(255, 0, 0), thickness);
}
} while (iter.Next(Tesseract.PageIteratorLevel.Para));
}
}

It takes about 20 seconds for each image. Their size are 1868*2416. Is there another way to detect block size instead of "iter = page.GetIterator()"? This command is very slow for me.

Regards
Zahra

@charlesw
Copy link
Owner

You can't, the page iterator is how you extract this information. There is
no alternative.

Is it the getiterator call itself that's taking 20 seconds or the iteration
loop?
On 25 Nov 2014 16:26, "azs-rahimi" notifications@github.com wrote:

Hi
I need to find position of each text block in image. I've read issue #64
#64 and #81
#81 and according to those,
my code is:

Tesseract.Pix pix = Tesseract.PixConverter.ToPix(testimg);
using (var page = engine.Process(pix))
{
using (var iter = page.GetIterator())
{
do
{
if (iter.TryGetBoundingBox(Tesseract.PageIteratorLevel.Block, out
blockBounds))
{
imgblock.Draw(new Rectangle(blockBounds.X1, blockBounds.Y1,
blockBounds.Width, blockBounds.Height), new Bgr(255, 0, 0), thickness);
}
} while (iter.Next(Tesseract.PageIteratorLevel.Para));
}
}

It takes about 20 seconds for each image. Their size are 1868*2416. Is
there another way to detect block size instead of "iter =
page.GetIterator()"? This command is very slow for me.


Reply to this email directly or view it on GitHub
#138.

@azs-rahimi
Copy link
Author

Calling the getitetator is about 20 sec for me. The loop is not slow (Up to one second).
Thank you again

@charlesw
Copy link
Owner

I think I know why it's taking that long and that's because getiterator is
actually doing the processing (on demand). You can verify that by just
calling Page.GetText() it should take around the same time.

If this is the case then you might be able to speed it up by changing some
parameters and try to trade accuracy for performance eg the page seg mode
or EngineMode.
On 25 Nov 2014 18:53, "azs-rahimi" notifications@github.com wrote:

Calling the getitetator is about 20 sec for me. The loop is not slow (Up
to one second).
Thank you again


Reply to this email directly or view it on GitHub
#138 (comment).

@azs-rahimi
Copy link
Author

I set EngineMode to "Default". It causes speeding up the getitetator calling .
Thank you Charles for your help

@azs-rahimi
Copy link
Author

I need more speed. Its run time is about 5 seconds. No other suggestion?

@charlesw
Copy link
Owner

Are you doing the processing concurrently? For instance multiple documents
at once.
On 27 Nov 2014 02:22, "azs-rahimi" notifications@github.com wrote:

I need more speed. Its run time is about 5 seconds. No other suggestion?


Reply to this email directly or view it on GitHub
#138 (comment).

@azs-rahimi
Copy link
Author

No, this time is just for one getiterator calling, and there is no other
process while it runs.

On Wed, Nov 26, 2014 at 11:03 PM, Charles Weld notifications@github.com
wrote:

Are you doing the processing concurrently? For instance multiple documents
at once.
On 27 Nov 2014 02:22, "azs-rahimi" notifications@github.com wrote:

I need more speed. Its run time is about 5 seconds. No other suggestion?

Reply to this email directly or view it on GitHub
#138 (comment).

Reply to this email directly or view it on GitHub
#138 (comment).

Azam Zahra Rahimi
M.Sc. Student at Ferdowsi University of Mashhad
Computer Engineering - Artificial Intelligence

@charlesw
Copy link
Owner

OK, this might just be how long it takes to process the image. Might be worth trying just running it through the tesseract.exe and seeing how long that takes.

@azs-rahimi
Copy link
Author

Do you mean I install the tesseract binary and run with it?

@azs-rahimi
Copy link
Author

I install tesseract -3.02.02 and run it. "tesseract MyPage.png outPage.txt -l eng"
It takes lower times about 3 seconds. But I can't find position of blocks. When I change the "psm" option, my outPage is 0 byte.

@charlesw
Copy link
Owner

Yes that's what I ment, idea was to get a baseline timing. I also forgot
that you could also use the gethocr functionality which should return an
xml blob with these values. Might be marginally faster given there
wouldn't be as much interop involved. However you would then need to parse
the output.

What's the use case here? I would have thought a couple of seconds would
have been acceptable in most cases?
On 29 Nov 2014 15:59, "azs-rahimi" notifications@github.com wrote:

I install tesseract -3.02.02 and run it. "tesseract MyPage.png outPage.txt
-l eng"
It takes lower times about 3 seconds. But I can't find position of blocks.
When I change the "psm" option, my outPage is 0 byte.


Reply to this email directly or view it on GitHub
#138 (comment).

@azs-rahimi
Copy link
Author

Could you please tell me how can I use the gethocr function.
I want to detect blocks and present to user. Then user selects any of them
(a desired block) for OCR process.

On Sat, Nov 29, 2014 at 1:02 PM, Charles Weld notifications@github.com
wrote:

Yes that's what I ment, idea was to get a baseline timing. I also forgot
that you could also use the gethocr functionality which should return an
xml blob with these values. Might be marginally faster given there
wouldn't be as much interop involved. However you would then need to parse
the output.

What's the use case here? I would have thought a couple of seconds would
have been acceptable in most cases?
On 29 Nov 2014 15:59, "azs-rahimi" notifications@github.com wrote:

I install tesseract -3.02.02 and run it. "tesseract MyPage.png
outPage.txt
-l eng"
It takes lower times about 3 seconds. But I can't find position of
blocks.
When I change the "psm" option, my outPage is 0 byte.

Reply to this email directly or view it on GitHub
#138 (comment).

Reply to this email directly or view it on GitHub
#138 (comment).

Azam Zahra Rahimi
M.Sc. Student at Ferdowsi University of Mashhad
Computer Engineering - Artificial Intelligence

@charlesw
Copy link
Owner

Okay, in this case I'd just do the following:

  1. Call Page.AnalyseLayout and use the resulting iterator to render your
    regions
  2. Once user selects the region they want set the region of interest and
    call get text or getiterator if you need additional information.

I don't think you'll be able to speed it up more than that.
On 30 Nov 2014 05:11, "azs-rahimi" notifications@github.com wrote:

Could you please tell me how can I use the gethocr function.
I want to detect blocks and present to user. Then user selects any of them
(a desired block) for OCR process.

On Sat, Nov 29, 2014 at 1:02 PM, Charles Weld notifications@github.com
wrote:

Yes that's what I ment, idea was to get a baseline timing. I also forgot
that you could also use the gethocr functionality which should return an
xml blob with these values. Might be marginally faster given there
wouldn't be as much interop involved. However you would then need to
parse
the output.

What's the use case here? I would have thought a couple of seconds would
have been acceptable in most cases?
On 29 Nov 2014 15:59, "azs-rahimi" notifications@github.com wrote:

I install tesseract -3.02.02 and run it. "tesseract MyPage.png
outPage.txt
-l eng"
It takes lower times about 3 seconds. But I can't find position of
blocks.
When I change the "psm" option, my outPage is 0 byte.

Reply to this email directly or view it on GitHub
<
https://github.com/charlesw/tesseract/issues/138#issuecomment-64941746>.

Reply to this email directly or view it on GitHub
<#138 (comment)
.

Azam Zahra Rahimi
M.Sc. Student at Ferdowsi University of Mashhad
Computer Engineering - Artificial Intelligence


Reply to this email directly or view it on GitHub
#138 (comment).

@azs-rahimi
Copy link
Author

I've used Page.AnalyseLayout() instead of Page.GetIterator(). It seems this function is faster than the GetIterator.
Thank you again Charles for your help

@charlesw
Copy link
Owner

No problem
On 30 Nov 2014 17:21, "azs-rahimi" notifications@github.com wrote:

I've used Page.AnalyseLayout() instead of Page.GetIterator(). It seems
this function is faster than the GetIterator.
Thank you again Charles for your help


Reply to this email directly or view it on GitHub
#138 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants