Google Vision OCR,将单词坐标从90、180、270个文档旋转到0度

如何解决Google Vision OCR,将单词坐标从90、180、270个文档旋转到0度

问题

鉴于我们有以下指南,摘自Google Vision OCR文档https://developers.google.com/resources/api-libraries/documentation/vision/v1p1beta1/python/latest/vision_v1p1beta1.files.html

                  "boundingBox": { # A bounding polygon for the detected image annotation. # The bounding box for the paragraph.
                      # The vertices are in the order of top-left,top-right,bottom-right,# bottom-left. When a rotation of the bounding box is detected the rotation
                      # is represented as around the top-left corner as defined when the text is
                      # read in the 'natural' orientation.
                      # For example:
                      #   * when the text is horizontal it might look like:
                      #      0----1
                      #      |    |
                      #      3----2
                      #   * when it's rotated 180 degrees around the top-left corner it becomes:
                      #      2----3
                      #      |    |
                      #      1----0
                      #   and the vertex order will still be (0,1,2,3).

因此,作为一项实验,我从四个不同方向扫描了同一文档,并通过Google的Vision OCR(DOCUMENT_TEXT_DETECTION)对其进行了处理。即0、90、180和270度。从Google的OCR输出中可以得出以下结果。

0度方向的文档。 这是水平文本的默认设置。它具有0度的文字旋转角度。这是四个角落:

0----1
|    |
3----2
Document height 3508
Document width 2479

输出文字示例

LEGO - {'vertices': [{'x': 755,'y': 172},{'x': 877,'y': 173},{'x': 876,'y': 237},{'x': 754,'y': 236}]}
LEGOLAND - {'vertices': [{'x': 1994,'y': 189},{'x': 2269,'y': 192},{'x': 2268,'y': 244},{'x': 1993,'y': 241}]}

文档呈90度角。

1----2
|    |
0----3
*vertex order will still be (0,3)
Document height 2479
Document width 3508

输出文字示例

LEGO - {'vertices': [{'x': 170,'y': 1730},{'x': 171,'y': 1604},{'x': 241,{'x': 240,'y': 1730}]}
LEGOLAND - {'vertices': [{'x': 188,'y': 486},{'x': 192,'y': 213},{'x': 245,'y': 214},'y': 487}]}

文档方向为180度。

2----3
|    |
1----0
*vertex order will still be (0,3)
Document height 3508
Document width 2479

输出文字示例

LEGO - {'vertices': [{'x': 1740,'y': 3337},{'x': 1584,'y': 3336},{'x': 1585,'y': 3259},{'x': 1741,'y': 3260}]}
LEGOLAND - {'vertices': [{'x': 485,'y': 3315},{'x': 212,'y': 3311},{'x': 213,'y': 3261},{'x': 486,'y': 3265}]}

文档具有270度的方向。

3----0
|    |
2----1
*vertex order will still be (0,3)
Document height 2479
Document width 3508

输出文字示例

LEGO - {'vertices': [{'x': 3335,'y': 738},{'x': 3333,'y': 893},{'x': 3269,'y': 892},{'x': 3271,'y': 737}]}
LEGOLAND - {'vertices': [{'x': 3318,'y': 1994},{'x': 3313,'y': 2266},{'x': 3261,'y': 2265},{'x': 3266,'y': 1993}]}

现在是问题/问题

鉴于我们有一个以90度,180度和270度扫描的文档,该如何在数学上旋转坐标,以便无论以哪个方向扫描,它们都得到与默认0度文档相同的结果。或者换句话说,如何像将其以0度扫描一样,更正90、180和270度的坐标?

对于某些人来说,这个问题似乎很简单,但过去几天我一直在尝试各种方法,但似乎无法解决。

因此,输入参数为扫描的页面方向度(0,90,180,270),Google OCR输出的文本顶点以及Google OCR的页面大小(高度和宽度)。

输出必须是页面方向为0度的校正文本顶点

解决方法

我会给你数学上的答案。请记住,数学是一门精确的科学,而视觉OCR扫描是一种经验技术,即不是精确的科学。

请允许我举一个简单的示例,以便您查看行为。想象一个文档的高度为10,宽度为4,在坐标(1,9)处有一个点。将其旋转90º时,该点的坐标变为(9,3),然后变为(3,1),最后变为(1,1)。

原因是,对于高度 H 和宽度 W 的通用矩形,点(a,b)旋转90º会产生:
(a,b)->(b,W-a) W'= H,H'= W

反复进行此转换将产生180º,270º转换。
就是序列(a,b)->(b,W-a)->(W-a,H-b)->(H-b,a)->(a,b)

因此,假设您已经知道所有参数,那么从序列中的任何一点将其转换回(a,b)只是一个简单的方程式。

例如,对于您的180º度边界框:

LEGO - {'vertices': [{'x': 1740,'y': 3337},{'x': 1584,'y': 3336},{'x': 1585,'y': 3259},{'x': 1741,'y': 3260}]}
  • 每个 x 值均遵循 x = width-x0-> x0 = width-x
  • 每个 y 值均遵循 y =高度-y0-> y0 =高度-y

哪个给:

LEGO - {'vertices': [{'x': 739,'y': 171},{'x': 895,'y': 172},{'x': 894,'y': 249},{'x': 738,'y': 248}]}

当然,这与您的原始值略有不同。如果对所有旋转执行简单转换,则可以看到它们在所有旋转中都略有不同。请记住,这是经验性的“边界框”,它们具有关联的错误,不可能像对待“数学”问题一样使它们相同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-