使用python提高图像质量

时间:2017-09-18 09:05:36

标签: python opencv ocr tesseract

我的任务有问题。我需要使用python + tesseract从图像中获取文本。但是图像的质量并不高 - 它的屏幕截图。

我正在使用OpenCV lib并且有两个变体:

  1. COLOR_BGR2GRAY
  2. ADAPTIVE_THRESH_GAUSSIAN_C | THRESH_BINARY
  3. 这个变种的工作不正确。

    当我将图像二值化时

    
    def binarize_image(img_path, threshold=195):
        """Binarize an image."""
        image_file = Image.open(img_path)
        image = image_file.convert('L')  # convert image to monochrome
        image = np.array(image)
        image = binarize_array(image, threshold)
        im = Image.fromarray(image)
        im.save(img_path)
        # imsave(target_path, image)

    def binarize_array(numpy_array, threshold=250): """Binarize a numpy array.""" for i in range(len(numpy_array)): for j in range(len(numpy_array[0])): if numpy_array[i][j] > threshold: numpy_array[i][j] = 255 else: numpy_array[i][j] = 0 return numpy_array

    tesseract通常不会得到文字。

    我如何解决它的问题?

    screenshot example

    UPD:解决了我的问题,我需要在两个字母之间添加一些像素。截图字母为白色,背景为黑色。我怎么能用numpy来做呢?

0 个答案:

没有答案