Changing a String of Text and Numbers into Just Numbers

喜夏-厌秋 提交于 2020-01-04 05:57:07

问题


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:

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'.

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) Import your Sikuli libraries into your java project

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

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

Thanks in advance for any help!


回答1:


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:

Option 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...

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

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

Option 2:

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.




回答2:


Figured out a solutions for this...

    String transactionId = "1lJ1BT0357317IJ253 ";

    System.out.println("Before Conversion: " + transactionId);

    transactionId = transactionId.replace("lJ","0");
    transactionId = transactionId.replace("IJ","0");
    transactionId = transactionId.replace("B","8");
    transactionId = transactionId.replace("T","7");
    transactionId = transactionId.replace(" ","");

    System.out.println("After Conversion: " + transactionId);

Seems to get the job done for me...Hope this helps others.



来源:https://stackoverflow.com/questions/33291954/changing-a-string-of-text-and-numbers-into-just-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!