将文本和数字的字符串更改为正数 [英] Changing a String of Text and Numbers into Just Numbers

查看:114
本文介绍了将文本和数字的字符串更改为正数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Sikuli API中的OCR工具从以下屏幕查找交易ID:

I'm currently using the OCR tools in Sikuli API to find a transaction ID from the following screen:

它会查找文本并在进行一些清理后返回以下内容:

It finds the text and returns the following after a little bit of cleanup:

我的问题是...如何最好地将OCR生成的字母字符替换为正确的数字?从我所看到的,它与解密字母的方式是相当一致的.例如,"0"通常以"1J"结尾,"6"变成"b",而"7"变成"T".

My question is...How would one best replace the letter characters generated from the OCR with proper Numbers? From what I can see, its fairly consistent with how it deciphers the letters. For example, a '0' usually ends up '1J', a '6' turns into a 'b', and a '7' turns into a 'T'.

对于那些感兴趣的人,我将发布我用来使OCR正常工作的代码,因为与此相关的大多数信件都已使用2年以上.

For those that are interested, I'll post the code I used to get the OCR to work as most correspondences about this are more then 2 years old.

1)将Sikuli库导入到Java项目中

1) Import your Sikuli libraries into your java project

2)在班级顶部,将设置设置为TRUE

2) At the top of your class, set the settings to TRUE

3)设置图像以使其锚定并执行以下代码.

3) Setup you image to anchor off of and do a variation of the following code.

在此先感谢您的帮助!

推荐答案

我使用与@zerotres自己提出的解决方案相同的解决方案,但没有发现任何更好的解决方案.仅需考虑的几点可能会提高检测质量:

I use the same solution as @zerotres proposed myself and meanwhile didn't find anything better. Just few more points to consider that might improve the detection quality:

选项1 :

  1. 确保包围文本的区域不包括任何不相关的区域,例如,文本周围的框架(如问题中所显示的那样),等等.

  1. Make sure that the region enclosing the text doesn't include any unrelated areas, for example the frame around the text (as it appears in the question), etc...

有时候,这将有助于使该区域在感兴趣的区域内稍微移动.

Sometimes it will help moving the region slightly around the area of interest.

在两种情况下都使用region.highlight(seconds)有助于确定该区域确切覆盖了什么.

In both cases using region.highlight(seconds) can be helpful to determine what exactly is being covered by the region.

选项2 :

有时,检测到的文本不可挽救,并且字符替换将不起作用.在这种情况下,可以考虑使用其他方法.如果您在感兴趣区域附近有一些静态视觉图案,则可以将其用作枢轴以定位文本区域.然后,如果您要抓取的文本是可单击的,则只需选择文本(例如,双击),然后从剪贴板中读取文本.这将导致100%正确的结果.

Sometimes, the detected text is unsalvageable and character replacement won't work. In such cases, a different approach might be considered. If you have some static visual pattern near the region of interest, you can use it as a pivot to locate the area of the text. Then, if the text that you are trying to scrape is clickable, you can just select the text (with double click for example) and then read it form the clipboard. That will result in 100% correct outcome.

这篇关于将文本和数字的字符串更改为正数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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