OCR detection and trimming functions