Ticket #408 (assigned enhancement)

Opened 1 year ago

Last modified 1 week ago

Not reading text properly with skewed image

Reported by: bleblanc@fedchex.com Assigned to: decoder (accepted)
Priority: major Milestone:
Component: Image Analysis Version: 3.5.1
Keywords: Skewed Image Cc:

Description

This problem is not directly with Fuzzy OCR, but I thought this would be a good place to ask my question. I have installed gocr, ocrad and tesseract-ocr and none of these applications will process my spam images. These images are the typical Viagra/pill spam messages that have only a gif image and a bunch of random text. The problem is the orientation of the image. The image is skewed at an angle on a white background. When I run it through any of these ocr apps, I get a bunch of garbage as output. I am assuming that this is because of the angle of the image. Has anyone run into this type of image?

Also, I did not know if it would be appropriate to attach the image, so I did not. Please let me know if anyone would like a sample image, so they can see what I am talking about.

Thanks, Brian

Attachments

FuzzyOcr_skew_correction.20070828_1.diff.gz (2.6 kB) - added by Dan Larsson on 28.08.2007 08:43:50.
FuzzyOcr? skew correction patch

Change History

11.08.2007 16:48:00 changed by decoder

  • status changed from new to assigned.
  • type changed from defect to enhancement.

Hello,

I am aware of these new rotated images, but I currently do not have the time to implement checks into FuzzyOcr? to catch them.

There is a possibility though for you, to rotate images using the preprocessor/scanset settings, for example using pnmrotate.

pnmrotate - rotate a PNM image by some angle

An example:

In the preprocessor file:

# Rotates a PNM by 7 degrees preprocessor rotate {

command = pnmrotate args = 7

}

And in the scanset file:

# Inverted Ocrad scanset with rotation scanset ocrad-invert {

preprocessors = rotate command = $ocrad args = -s5 -i $input

}

With these additions, you can now scan images after rotating them by a given angle. The problem here is that often, these rotations are arbitary and would require some kind of detection first to find out the angle for rotation. This can be achieved with image analysis but is very complex. When I have more time, I can maybe implement this, but at this time, I can't.

Best regards,

Chris

11.08.2007 16:49:32 changed by decoder

here the code snippets again, properly formatted:

# Rotates a PNM by 7 degrees
preprocessor rotate {
    command = pnmrotate
    args = 7
}

# Inverted Ocrad scanset with rotation
scanset ocrad-invert {
    preprocessors = rotate
    command = $ocrad
    args = -s5 -i $input
} 

15.08.2007 15:27:54 changed by anonymous

Is that 7 degrees clockwise or 7 degrees counter-clockwise?

I would like to catch it if they just rotate the image 7 degrees in the other direction at the same time, if at all possible.

Thanks

(follow-up: ↓ 5 ) 19.08.2007 20:10:22 changed by Dan Larsson

A better (atleast to me) solution would be to detect the skew angle and rotate the image accordingly. One way of detecting is to use pbm_findskew which is included in the pagetools package http://sf.net/projects/pagetools, the app is not bulletproof but did detect the skew angle for most of the skewed images I tested with.

With the skew angle known it's just a matter of feeding it to the rotate preprocessor :-)

(in reply to: ↑ 4 ; follow-up: ↓ 6 ) 20.08.2007 21:55:33 changed by anonymous

Can you put in the code snippets you used for FuzzyOCR like decoder did above? I'll see if I can duplicate your success. :)

(in reply to: ↑ 5 ) 24.08.2007 16:03:01 changed by Dan Larsson

My tests didn't include hooking up FuzzyOcr?, I'm still investigating (when time permits) different alternatives. If you'd like to do the same tests I did use something similar to:

% giftopnm image.gif | pamditherbw -threshold | \
     pnminvert | pgmtopbm >temp.pbm && \
     pbm_findskew temp.pbm > temp.skewangle && \
     pnmrotate -noantialias `cat temp.skewangle` temp.pbm | ocrad
% rm -f temp.*

Compare the result from the above with the same image not rotated.

28.08.2007 08:43:50 changed by Dan Larsson

  • attachment FuzzyOcr_skew_correction.20070828_1.diff.gz added.

FuzzyOcr? skew correction patch

28.08.2007 09:13:16 changed by Dan Larsson

Alright, I've created a patch (against svn rev 133) that enables FuzzyOcr? to correct skewed images. Make sure you have pnmrotate, pgmtopbm, ppmtopgm and pbm_findskew installed, it won't work otherwise. As mentioned before, pbm_findskew is a part of the pagetools project on SourceForge? <http://sf.net/projects/pagetools/>.

Please note that the code is ALPHA quality, meaning I've only tested it on servers which I control (All of these run spamd from SpamAssassin? v3.2.3 under perl v5.8.8). In other words, it might not work on your system/server enviornment at all, for any number of reasons and thus must not be applied to machines in production. Besides, the patch has not been approved by the FuzzyOcr? developers so it might be thrown away completely or for a completely different solution.

You have been warned!

However, if you want to test it, you can download from this ticket.

Patch MD5: 51735eb8d3a50f5eb3c7ab1cc3bc3061
Patch SHA256: 5b059a9614860bc40cf6e1d558414c1b7a4d0898eecc29644d690668ac3e4c21

13.08.2008 10:02:56 changed by anonymous

I'm closing it according to the last comment.
----------
eric air max


Add/Change #408 (Not reading text properly with skewed image)