Tess4J - Follow a pattern

Hi guys. I have a couply of hunderd pictures, all taken exactly the same, lighting composition etc. I select a segment of these images that contains a label. However sometimes the label is read ~90% okay, but sometimes just not at all, or only 20% correct. Now I was thinking that perhaps it is possible to tell the node to follow a certain pattern, as th elabels have a lot of overlapping characters. The first 7 characters are the same for the entire batch, as they identify this batch. Only the last 4 characters differ between images, and they are always digits. Are there ways to force Tess4J to take this into account?

ps. the first 7 characters also include digits, so just only reading digits and not letters wouldn't be an option.

Hi Luuk!

You you probably be able to split the image so you only run the OCR on the last 4 digits. This also lets you use the digits option which should improve the results and possibly even performance.

In the end you can just combine the result with the 7 characters of the batch.

I hope that helps!

Regards, Jonathan.

Hi Jonathan,

I currently only run OCR on the portion of the image that contains the label itself, because label placement is not 100% accurate. Therefore I fear setting an arbitrary rectangle will sometime miss a bit of the number, or sometimes take characters from the first 7 characters. Would there be another option, although the simplicity of your suggestion is realy neat.



Hi Luuk, 


a very complex solution would be to "train tesseract" with the labels which would then create a language which can be used in the OCR node. I suspect this would be overkill for anything other than large scale long term projects. I cannot really help you with this, since I have not tried this myself.

Other than that, have you considered the preprocessing steps suggested in the node description? Usually some local (/adaptive) thresholding can improve the results. I read somewhere that tesseract applies some Otsu thresholding itself, too, though.

You may also want to took at https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality which may contain some hints on how to get better results.


Regards, Jonathan.

I wasn't aware of that link, thank you very much. I'll have a look at it. I already found out that I should get a different camera, in which I can fix the shutter time, as there is variation in that because of variation of the amount of subjects in the autofocus box of the camera, which results in different shutter times, which results in diferent light intensities. This all in turn results in different results because of my manual threshold.



I think I got it pretty much done, but how do I invoke the Bazaar command that is mentioned on Github>


This is currently not possible with the Tess4J Node, sorry. This should be pretty simple to implement, but I will probably not have time before the 8th of February.

Not a problem, I'm not that much in a hurry ;).

Indeed I think a simple checkbox would do, perhaps better to put it somewhere else then the main options, as to avoid confusion and people finding out it doesnt work.

Hi Jonathan,

did you by any chance have a look at this already?


Hi Luuk,

sorry, no, I did not. I will have a look at it on Monday after the KNIME Summit, if that is okay for you.

Regards, Jonathan.

Hi Jonathan,

That will be fine. Have fun during the Summit.


Hi Luuk!

This took me two days, but now I believe I have a very good solution. In a release in not too distant future, your Tess4J node will have a new node dialog tab which for your case should be configured to look like this:

String Manipulator

I attached the corresponding config file you can import instead of putting in the values manually.

This should expose all functionality of tesseract, I also found http://www.sk-spell.sk.cx/tesseract-ocr-parameters-in-302-version, which lists all possible configuration variables. So, if you need to know how to do something with the tesseract node, you should be able to instead generally search how to do it with tesseract (which should get you alot more results).

If you find any bugs, let me know!

Regards, Jonathan.

PS: I will write another post as soon as a new version has been released.


and all this fantastic work of jonathan is part of our tomorrows nightly build. Thanks Jonathan!!

For me the link in the node description doesn't work. Probably this is not something related to the node, but more embedded in the system. I also ecountered a similar problem here: https://tech.knime.org/forum/knime-image-processing/featur-calculator-bug

Also perhaps it is possible to increase the heigth of the input boxes a bit, as the underscore becomes invisble whilst typing. When you leave the box it is visible again. Also see screenshot. The first param is entered, and the second is being typed.

I tried to run the node, whilst I had a Key without a value. The node failed, showing a red bullit with a cross in it. Then I opened the config, closed it and ran it again. Now there is a key, but there is no associated value field. Using the Remove and Clear buttons didn't remove the Key. Only adding a new Key gave the old Key a value, after which it could be removed. Maybe error handling can be a bit improved here.

I was unsure about how to deal with the suffixes, whether or not to include the .txt extension my computer gives the wordpad files. Then screenshot 14 happened.

Whilst running a small set of images I don't see the results that I would expect.

My user-patterns contains only 1 line:


My user-words contains only 1 word


The config I have is attached to the post. I don't see what is going wrong here, but the result is as in the screenshot



PS. If anyone wants info on how to code the pattern I found this great answer on SO: http://stackoverflow.com/questions/17209919/tesseract-user-patterns

Hi Luuk,

first of all, thank you for all the valuable feedback!

> For me the link in the node description doesn't work.

Thank you for noticing, (the link is the same as in my forum post, by the way.)

> Whilst running a small set of images I don't see the results that I would expect.

It would be great, if you could quickly try running it without the config and tell me if it gives you the same result.

I will try to fix this ASAP, but probably won't be able to do so before Monday.



Removed the config, this is the result (screenshot)

After checking with the previous screenshot, results are 100% match.

Hi Luuk, 

I asked, because I suspected that the variables were not set correctly, but that does not seem to be the case, so your settings just don't actually do much for your use case. The other issues should be fixed/prevented and available in tomorrows nightly build.

The .user-conf and .user-word files need to be in the tessdata path. You will probably have to set the tessdata path appropriately in the node config.

Also, I recommend looking at the config presented in the wiki, since yours does not turn off loading the language dictionary.

Hope that helps and regards, Jonathan.