My program parses a line of text. In the following picture, I have drawn the bounding boxes around each char as coming from the Tesseract result iterator:
Apparently Tesseract has some problems segmenting the last character ('5') in the line, detecting 3 bounding boxes.
The last character is in fact a tad larger than the other characters, but why would Tesseract segment that character so differently when the pixel blob is thresholded so clearly?
I have set these Tesseract variables:
tess.setVariable("save_blob_choices", "1");
tess.setPageSegMode(PageSegMode.PSM_SINGLE_LINE);
tess.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, "0123456789"
and textord_min_xheight set to the pixel height of the above image
Any suggestions?
I did not find any solution to this problem. Tesseract is so badly documented.
I ended up finding the contour of every character and then passing each sub-image of a character to Tesseract, with the page segmentation mode PSM_SYMBOL. In the end, this was also twice as fast as the previous method!
Related
I've built a matrix of LEDs controlled by a Java program on my Raspberry Pi. I want to display characters on this matrix. So what I need to do is convert the characters to a two-dimensional boolean-Array (each LED is represented by one boolean).
The only way to do this I can think of is to design a separate matrix for each existing character, but this is way to much work.
Is there any way to do this differently?
You could rasterize (draw) a given font at a given point size using something like AWT or FreeType and then examine the image to see which pixels/LEDs should be on or off.
This will break down as the font size gets smaller. Below some point, you're probably better off coming up with the matrixes yourself rather than pouring a bunch of effort into something that doesn't work.
OTOH, "render-and-read" would be Much Less Boring... so YMMV.
you could load a monochrome image for a character with a pixel size regarding to your led matrix and check with two for loops, whether a pixel at a certain position is black (true) or white (false).
I'm trying to make a specific image filter, processing a picture to cartoonize and change the colors.
Here you can see the original and the expected result:
http://codingfocus.com/ieffect.jpg
I'm not sure which will be a good approach, I started with a grayscale, posterize and color replacement ranges based on how dark is every pixel, but the result is pretty pixelated and not near to what I would like to obtain.
http://codingfocus.com/test3.jpg
I'm currently trying both with php gd, imagemagick and jhlabs library for java.
Any advice would be appreciated.
Instead of replacing with a range of grayscale, convert in HSV color space and use a range based on channel H (hue).
If you want to remove the pixelated effect you can simply blur the result, or pheraps before the posterize effect too to remove the noise.
In ImageMagick, this gives somewhat similar effect.
Input:
convert faces.jpg -colorspace gray -kuwahara 3 -unsharp 0x2+4+0 \( xc:blue xc:red xc:yellow +append \) -clut result.jpg
Or without the 3 color lookup table:
convert faces.jpg -kuwahara 3 -unsharp 0x2+4+0 result2.jpg
See http://www.imagemagick.org/discourse-server/viewtopic.php?f=4&t=26480. But it requires version 6.8.9.9 or higher for the kuwahara filter.
I've been working on a simple OCR project for a couple days. The app is supposed to extract a text from an image. The solution I've come up with is:
greyscaling, rotating, removing noise from the image and isolating every single character on the image. So I need some help with a simple algorithm that would let me recognise the character. I only need to recognise the letters A,B,C,D.
The method i'd use would be to make a mask of each letter, scaling it to the rectangle you found when cutting the picture and "score" each letter, by comparing RGB for example.
I'm working in Java and trying to read text from images. I know the font and the size (Small, 8pt) of the text. These aren't scanned images and the text will never be slanted or italicized etc. I've looked into Java based OCRs, but I really don't need an entire OCR library/program and I would like to write it myself anyway.
My search to see if this has been asked already lead me here: Text Extraction from an Image Using java. I don't really know how to go about region matching.
The solution I was trying was to first adjust contrast/brightness or otherwise get rid of anti-aliasing, then split the image up into images of characters using the empty vertical line of pixels between each character as a delimiter, then use some algorithm match each character individually. The problem is I've found some pairs of letters do not have any space in between to determine where one starts and the other ends.
Here's an example of the text. The 'f' characters are examples of characters that don't have space in between them.
if you do manage to find the first "f" why don't u stop and continue the search by giving it a checkpoint that you know of. To make it general for all the unwanted connections
1. You can use the best matching checkpoint
2.you can go forward then when you lost a match go back and forth from the initial and final points you get by checkin them simelteniosly.
I need to draw a text line where some specified characters would be replaced by arbitrary polygons. These polygons must be painted with Graphics directly using drawPolygon. method. While Unicode contains a range of graphical symbols, they are not appropriate for this task.
I was wondering if it was possible to replace a character with a polygon, in any instance of that character's occurrence in a string?
For example, if I typed-in the word 'Holly' and hit 'enter', the first letter would be replaced by the polygon.
If I then went to type the word 'thistle', the polygon's new position would be in place of the second letter?
Any help/guidance will be greatly appreciated.
Assuming the actual polygon is represented in Unicode all you have to do is string replacement.
System.out.println("Hello".replace('H', '\u25C6'));
produces
â—†ello
If you want to display a polygon, may be the easy way is to choose a Unicode symbol
There are lots of them with graphic contents (even a snow man)
This is fully doable with FontMetrics that allow to measure the dimensions of the string as printed with the given font. Use FontMetrics to determine to compute the locations of the string fragments and then draw the string fragments and polygons in between.
This approach seems reasonable if the polygons must be somehow very special (maybe non-Unicode characters?), or they required dimensions are very different from the letter dimensions in the used font.
In early days of Java when the Unicode support was yet not very good, it was not uncommon to draw unsupported national characters that way.