Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect orientation of a scanned document?

I'd to detect and, if necessary, correct the orientation of a scanned document image. I am already able to deskew documents, however it still might occur, that a document is upside down and it needs to be rotated by 180°.

Using tesseract's layout analysis feature it should be possible to determine a document's orientation using this code:

    tesseract::TessBaseAPI api; 
    api.Init(argv[0], "eng");
    api.SetImage(img); 
    api.SetPageSegMode(tesseract::PSM_AUTO_OSD); 
    tesseract::PageIterator* it = api.AnalyseLayout();

    tesseract::Orientation orient;
    tesseract::WritingDirection dir;
    tesseract::TextlineOrder order; 
    float f;
    it->Orientation(&orient, &dir, &order, &f); 

    if(orient == tesseract::Orientation::ORIENTATION_PAGE_UP)
        std::cout << "Page Up\t"; 
    else if(orient == tesseract::Orientation::ORIENTATION_PAGE_LEFT)
        std::cout << "Page Left\t"; 
    else if(orient == tesseract::Orientation::ORIENTATION_PAGE_DOWN)
        std::cout << "Page Down\t"; 
    else if(orient == tesseract::Orientation::ORIENTATION_PAGE_RIGHT)
        std::cout << "Page Right\t";

However the code doesn't seems to work correctly as it always returns ORIENTATION_PAGE_UP when a document is in portrait format and ORIENTATION_PAGE_LEFT when it is in landscape format. (ORIENTATION_PAGE_DOWN and ORIENTATION_PAGE_RIGHT can be used, but are never returned).

A.) Is there anything wrong with the code above?

B.) How else can I determine a documents orientation?

like image 324
Pedro Avatar asked Nov 17 '11 20:11

Pedro


People also ask

Why is my scanner scanning things upside down?

Your product scans using the Auto Photo Orientation setting. This setting checks the preview image for faces, the sky, and other features, and then correctly rotates the photo when it is scanned, if necessary.

Why does my scanner scan sideways?

If your output documents are crooked (skewed), there are several possible reasons: The original documents were not loaded properly or the document guides were not properly adjusted. It may be necessary to enable [Automatically straightens skewed] in the scanner driver settings.

How do I rotate a document in ScanSnap?

Select [Open with ScanSnap Home Viewer] in the menu that appears when you right-click the content data record to display the viewer window. Select a page to be rotated. When the view mode for the viewer window is [Show all] or [Show Pages Panel], you can rotate multiple pages all together.


1 Answers

What about just running your detection evaluate the detection rate and then doing the same thing flipped ? The better rate gives the right direction.

like image 171
Martin Avatar answered Oct 12 '22 07:10

Martin