how to detect orientation of a scanned document?

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

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?

回答1:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!