how to extract numeric values from jpg file using OCR - java

I have created the below code and executed:
Ocr.setUp();
Ocr ocr = new Ocr();
ocr.startEngine("eng", Ocr.SPEED_FASTEST);
String s = ocr.recognize(theImage, Ocr.RECOGNIZE_TYPE_ALL, Ocr.OUTPUT_FORMAT_PLAINTEXT);
ocr.stopEngine();
Output:
Result: L‘i
L‘L’Ui l
Actually the image only contains the numeric values. Is it possible to extract only numeric value by using above code?
I have 1234 numeric value displayed in jpg file, I just want to print that numeric value in o/p console. Can anybody help me out?

I have a few technology-independent observations about your code.
"SPEED_FASTEST" indicates your preference for fast OCR. Fast is the opposite of High-quality. You either get speed or quality. If the image is clear - no problem, but if the image is less than perfect, Quality mode will have more algorithms to deal with defects.
Nowhere in your code it is specified that you constrain the character set to digits only. If you do not indicate the language or character set, then usually by default the entire English character set is used. See my response on this post here: OCR why not find only character
Typically if you post a sample image along with your question and code, contributors can give you better advice.

Related

openCV java compareHist() value larger than 1

I am learning openCV and when I tried to compare 2 histograms and print the result the values coming were actually larger than 1. Sorry if it is a stupid question but I am still learning.
Output showing those values:
enter image description here
as you can see in the image the values are in thousands .
Thanks a lot
The third argument of the compareHist method selects the comparison function. In your case, the Chi-Square function is used to compare the two histograms, which does not have an upper limit. You could use the correlation comparison function (CV_COMP_CORREL, 0), which is bound between -1 and 1. See also this question on the OpenCV stack exchange.

Torch-rnn sample.lua binary file exporting

I've been experimenting with Torch for a while now, and I wrote my own audio file format.
In that I want to have my data stored in bytes, so I would use all 256 possible values in the file.
I put my file in preprocess.py with 'bytes' encoding, it threw no exceptions. The training goes well, too, but when I'm generating sample data, it is not really bytecode. Some of the characters are written out and some byte values are just in brackets.
[158][170][171][147][164][199][201][179][170][185][184][163][134][130][151][164][150][130]xnjlbUQcq]Vg|ysx{[130]|svzv[144][168][152][137]m[136][150][134][135][135][177][167][130][128][150][167][159][146][132][131][135]Wm{[155]}mqm[143]x[138]r[140][131][135]yv[135]}enj[138][145][141][140][150][128]mrj[132]vv[133][150][152][155][136][140][159][149][152][131]{[139]wmTPQ\bqveMYk[128]uvt[141][147][139][132][132][143][143][132][148][178][187][174][166][164][150]zt[137]xeo~xjt|x~zxx[130]tgp}[147][141][137][139]
How could I change sample.lua's output? I did make a change but I do not know Lua. This is what I wrote:
local sample = model:sample(opt)
local out = io.open(opt.output, "wb")
out:write(sample)
out:close()
instead of
local sample = model:sample(opt)
print(sample)
That resulted the same output. What could I do to get it working?

Changing a String of Text and Numbers into Just Numbers

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!
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:
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.
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.
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.

how to use cell.getArabicOption(int arabicoption)

i don't know what the integer can i use it in this function
so i have a problem to show arabic in my creating pdf
i use iText library to get this function
if some on know how to use it please inform me
You shouldn't use int values such as 0, 1, 2,... in your code as it will be very hard for people to know what these values mean (just like you currently have no idea which options are available).
Instead you should use constants that are provided by iText. The API documentation informs you that the parameters for the setArabicOptions() method can be a combination of:
ColumnText.AR_NOVOWEL: Eliminate the arabic vowels,
ColumnText.AR_COMPOSEDTASHKEEL: Compose the tashkeel in the ligatures, or
ColumnText.AR_LIG: Do some extra double ligatures.
If you want to know which exact int values correspond with these constants, you can always print them out or look inside the code, but there is no reason to do this.
The different values are actually to be used as flags (or bits). You can combine these values like this:
column.setArabicOptions(
ColumnText.AR_NOVOWEL |
ColumnText.AR_COMPOSEDTASHKEEL |
ColumnText.AR_LIG);

Random GUID in Java (A different format)

One of the components that I use needs to feed an XML into it. The component provider has not provided any documentation or the specs of the XML. I am trying to generate the XMLs by trial and error using the sample XMLs from the component.
This was the story. Here is my problem.
In the XML, they have used some f_key = "b3f39bb9-3f8c-453a-bdb4-2486a887e39f-0000a008:000001e8"
Java gives me this : UUID.randomUUID().toString()
which generates random strings in this format : "22572e59-f7dc-404a-9c0c-78161e3a4df7"
Any clue, what does "0000a008:000001e8" in the f_key provided by the component mean [The random string up to 5 pieces matches in both. The 6th and 7th piece are extra in the random string provided by the component]? What sort of UUID generator would be generating that? Does it look familiar?
According to this code
Regex guidRegEx = new Regex(#"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
guidRegEx.IsMatch("b3f39bb9-3f8c-453a-bdb4-2486a887e39f-0000a008:000001e8");
that isn't a valid guid, its a valid guid with something on the end. I am guessing they've tacked a timestamp on the end. I've seen stuff come out of timestamp appliances in the past.
But that is a best guess.
I believe that it is just some kind of key that is generated by the provider. Although I have no idea about the rules of the key generation (that is application specific) I translated hex numbers a008 1e8 to decimal view and found that the ratio between them is 83: 40968/488=83. So, probably try to create UUID and add suffix that consists of 2 numbers in hex format so that the ration of them is 83.

Categories

Resources