toleranceX = int(5 / 100 * boxWidth) toleranceY = int(5 / 100 * boxHeight) startX -= toleranceX startY -= toleranceY endX += toleranceX endY += toleranceY # draw the bounding box on the image # cv2.rectangle(orig, (startX, startY), (endX, endY), (0, 255, 0), 2) # get portion of image containing text crop = orig[startY:endY, startX:endX] # image pre-processing crop = OCR.preProcess(crop) # get text from ocr txt = (OCR.getText(crop)) boxes.append(((startX, startY, endX, endY), txt)) # simple block alignment algorithm # by finding ignorable difference between starting pixels # of each ROI def alignText(boxes, pixel, drawer): newBoxes = dict() for coord, txt in boxes: isPresent = False startY = coord[1] for i in range(startY - pixel, startY + pixel + 1):