Improve memory usage for OCR

A maximum resolution is now dynamically calculated so that the bitmaps don't exceed the 66.66% of the maximum heap size. This should solve most of the OutOfMemoryErrors.