如何检测扫描文档的方向? [英] how to detect orientation of a scanned document?

查看:345
本文介绍了如何检测扫描文档的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会检测并在必要时更正扫描的文档图像的方向。我已经能够校正文档,但仍然可能发生,文档是颠倒的,需要旋转180°。

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°.

使用 tesseract '可以使用以下代码确定文档的方向:

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";

然而,代码似乎不能正常工作,因为它总是返回 ORIENTATION_PAGE_UP ,当文档为纵向格式时, ORIENTATION_PAGE_LEFT (可以使用 ORIENTATION_PAGE_DOWN ORIENTATION_PAGE_RIGHT ,但不会返回)。

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。)上面的代码有什么问题吗?

推荐答案

如何确定文档的方向?检测率然后做同样的事情翻转?更好的速度给出了正确的方向。

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

这篇关于如何检测扫描文档的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆