tesseract icon indicating copy to clipboard operation
tesseract copied to clipboard

How to get page orientation?

Open tudorserbanuipath opened this issue 4 years ago • 6 comments

Hello,

I'm a bit confused about the proper way to get the page orientation with tesseract. I have tried the following:

using (var pi = page.AnalyseLayout())
{
    pi.Begin();
    return pi.GetProperties().Orientation;
}

But it always returns PageUp.

I have also tried page.DetectBestOrientation(out int orientation, out _) but this returns 270 even for a page that is supposed to be PageUp.

tudorserbanuipath avatar Mar 02 '21 08:03 tudorserbanuipath

@charlesw Can you help please?

tudorserbanuipath avatar Mar 31 '21 11:03 tudorserbanuipath

See tests in Tesseract.Tests/AnalyseResultTests.cs for usage examples. From memory you need to use osd language for this to work.

Also make sure you use using statements to ensure resources are release.

On Wed, 31 Mar 2021, 22:05 tudorserbanuipath, @.***> wrote:

@charlesw https://github.com/charlesw Can you help please?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/charlesw/tesseract/issues/543#issuecomment-810978490, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB7HSBXQEUN6F4TLJDDJELTGL6XNANCNFSM4YOMMJSA .

charlesw avatar Mar 31 '21 20:03 charlesw

@charlesw: I tried the methods in the samples before but none of them worked for me. Maybe I can send you a sample file?

tudorserbanuipath avatar Apr 01 '21 12:04 tudorserbanuipath

@tudorserbanuipath You need to have "osd.traineddata" file in the tessdata folder and when initializing the engine set language to "osd" - this worked for me to detect orientation e.g. using var engine = new TesseractEngine(@"./tessdata", "osd", EngineMode.Default);

Olby2000 avatar Jun 16 '21 16:06 Olby2000

@tudorserbanuipath You managed to get it work? I'm facing the very same issue.

@Olby2000 when i added that traineddata file the orientation stayed the same, but the confidence dropped from 250 to <10. Could you point out difference in your implementation to my code snippet:

            using (var engine = new TesseractEngine(@"./tessdata", "osd", EngineMode.Default))
            {
                using (var img = Pix.LoadFromFile([JPG File]))
                {
                    using (var page = engine.Process(img))
                    {
                        using (var pi = page.AnalyseLayout())
                        {
                            pi.Begin();
                            var ori =  pi.GetProperties().Orientation; //Always PageUp
                        }
                        page.DetectBestOrientation(out int orientation, out float confidence); //orientation always 270, cofidence now <10
                    }
                }
            }

samtigall avatar Sep 04 '21 13:09 samtigall

@samtigall Replace using (var page = engine.Process(img)) by using (var page = engine.Process(img, PageSegMode.AutoOsd))

kanashiilove avatar Sep 05 '22 13:09 kanashiilove