Ask Your Question
0

tesseract/opencv invert color conditionally?

asked 2016-07-03 07:47:08 -0600

atv gravatar image

While this almost has nothing to do with opencv, i thought id post this here in case someone has a good solution.

So i came up with some code for using tesseract with opencv, and it works pretty well. But, only black letters on white background. I tried doing a bit flip_not(src,dst) but that, while it works, obviously just swaps the situation.

Is there a way to invert the color conditionally? Say, invert when black letters on white and not invert when white on black ? Or threshold it ?

Thanks, Alef

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-03 08:12:50 -0600

Guanta gravatar image
  • simple binary documents (without images): then you can just use a simple heuristic: compute the mean of all pixels: if average > 128 --> black script on white paper.

  • simple documents (not binary, i.e. with gradients etc.): compute the image histogram, from the histogram compute the skewness (https://en.wikipedia.org/wiki/Skewness), if the skewness is negative --> black script on white paper.

  • non simple document image, i.e. containing image content etc: then you probably need to classify your image, probably a simple bag of (visual) words scheme will work quite good.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-03 07:47:08 -0600

Seen: 638 times

Last updated: Jul 03 '16