首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何才能得到右上角和右上角的坐标?

如何才能得到右上角和右上角的坐标?
EN

Stack Overflow用户
提问于 2021-08-31 16:44:56
回答 1查看 562关注 0票数 2

让我们来介绍一下背景。我正试图为我的应用程序达到一些价值,我需要拿起img的红色盒子。

我得到了这些单词的所有top_left和bottom_right坐标。

代码语言:javascript
复制
[Word(top_left=(608, 11), bottom_right=(821, 38), confidence=99.45719909667969, text='PANELBOARD'), 
Word(top_left=(25, 12), bottom_right=(106, 39), confidence=99.0506591796875, text='CH1L'), 
Word(top_left=(112, 12), bottom_right=(282, 44), confidence=97.45893859863281, text='(EXISTING)'), 
Word(top_left=(1264, 39), bottom_right=(1346, 55), confidence=83.25164031982422, text='208Y/120V,'), 
Word(top_left=(1350, 39), bottom_right=(1410, 55), confidence=94.61625671386719, text='3PH,4W'), 
Word(top_left=(1379, 60), bottom_right=(1412, 75), confidence=98.55554962158203, text='MLO'), 
Word(top_left=(92, 61), bottom_right=(215, 75), confidence=99.64352416992188, text='REFRIGERATED'), 
Word(top_left=(219, 61), bottom_right=(262, 75), confidence=99.87834930419922, text='CASE'), 
Word(top_left=(265, 61), bottom_right=(318, 75), confidence=99.78636932373047, text='LIGHTS'), 
Word(top_left=(320, 61), bottom_right=(331, 75), confidence=99.71800231933594, text='&'), 
Word(top_left=(19, 61), bottom_right=(87, 76), confidence=99.207763671875, text='SERVES:'), 
Word(top_left=(334, 61), bottom_right=(402, 76), confidence=99.7181625366211, text='RECEPTS'), 
Word(top_left=(1335, 61), bottom_right=(1376, 76), confidence=98.63665771484375, text='250A,'), 
Word(top_left=(18, 83), bottom_right=(104, 97), confidence=98.90849304199219, text='LOCATION:'), 
Word(top_left=(108, 83), bottom_right=(155, 97), confidence=99.3512954711914, text='COMP'), 
Word(top_left=(157, 83), bottom_right=(211, 97), confidence=99.74064636230469, text='HOUSE'), 
Word(top_left=(214, 83), bottom_right=(221, 97), confidence=97.91343688964844, text='1'), 
Word(top_left=(1376, 103), bottom_right=(1408, 118), confidence=98.71705627441406, text='BUS'), 
Word(top_left=(18, 104), bottom_right=(110, 118), confidence=99.58409118652344, text='MOUNTING:'), 
Word(top_left=(112, 104), bottom_right=(183, 118), confidence=99.85911560058594, text='SURFACE'), 
Word(top_left=(1210, 104), bottom_right=(1304, 118), confidence=99.44200134277344, text='EQUIPMENT'), 
Word(top_left=(1307, 104), bottom_right=(1374, 118), confidence=99.8482666015625, text='GROUND')]

当"MLO“的x大于"3PH,4W”,所以按x排序,然后按y排序时,问题就出现了(是的,OCR检测"3PH,4W“作为一个hehe)。

我试着遵循“右上角将有最小的差别”的规则,但它也没有起作用。

有解决办法吗?

耽误您时间,实在对不起。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-31 18:48:55

如果您知道这两种信息中的任何一种,那么这个问题很容易回答:

  • 指整体包围框右上角的坐标;
  • 是整个包围框的左上角右上角的方向矢量。

在前一种情况下,将B称为右上角的点,然后“最上右上角”点是最接近右上角的点;这是将欧几里德距离math.dist(B, P)最小化的点P

在后一种情况下,将v称为左上角对角线的方向向量,并将O = (0,0)设为原点,“最右上”点是使点积v.OP最大化的点P ( OP表示“向量OP”,与点P具有相同的坐标)。

在您的问题中,您没有给出右上角的坐标;但是,将对角线的方向向量近似为v = (1, -1)v和点P = (x,y)之间的点积就是x-y;因此,您可以这样得到带有“最右上”右上角的框:

代码语言:javascript
复制
>>> def toprightness(w):
...   return w.bottom_right[0] - w.top_left[1]
... 
>>> max(data, key=toprightness).text
'3PH,4W'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69002491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档