如何检测扫描文档的方向?

发布于 2024-12-16 18:22:55 字数 1320 浏览 3 评论 0原文

我会检测并在必要时纠正扫描文档图像的方向。我已经能够对文档进行歪斜校正,但仍然可能会发生文档颠倒的情况,需要将其旋转 180°。

使用 tesseract 的布局分析功能,应该可以确定文档的方向代码:

    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_DOWNORIENTATION_PAGE_RIGHT,但永远不会返回)。

A.) 上面的代码有什么问题吗?

B.) 我还能如何确定文档方向?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2024-12-23 18:22:55

只运行检测来评估检测率,然后翻转做同样的事情怎么样?更好的速率给出了正确的方向。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文