【发布时间】:2021-01-22 08:59:17
【问题描述】:
我正在使用 pytesseract 来确定图像上的单个字符。我正在使用image_to_boxes 函数,它为我提供了字符和坐标。但是,我需要将单个字符裁剪为单个图像文件。目前,下面的代码将创建边界框,但是我需要它来裁剪字符并将其保存到每个字符的单独图像文件中。
filename = 'image.png'
# read the image and get the dimensions
img = cv2.imread(filename)
h, w, _ = img.shape # assumes color image
# run tesseract, returning the bounding boxes
boxes = pytesseract.image_to_boxes(img)
# draw the bounding boxes on the image
for b in boxes.splitlines():
b = b.split(' ')
img = cv2.rectangle(img, (int(b[1]), h - int(b[2])), (int(b[3]), h - int(b[4])), (0, 255, 0), 2)
【问题讨论】:
标签: python image-processing ocr python-tesseract