如何检测扫描文档的方向?
我会检测并在必要时纠正扫描文档图像的方向。我已经能够对文档进行歪斜校正,但仍然可能会发生文档颠倒的情况,需要将其旋转 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_DOWN
和ORIENTATION_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.