dockerizing时openCV是否有任何问题?

时间:2019-05-10 05:06:30

标签: python docker opencv image-processing opencv-python

我在我的OCR(光学字符识别)应用程序中使用openCV来将具有(19,19)内核的GaussianBlur应用为预处理技术。 OCR在本地环境中运行良好。但是一旦被docker化就失败了。

具有(13,13)的内核在本地和dockerized环境中都可以正常工作。

import os
from PIL import Image
import pytesseract
import cv2

path = os.path.dirname(os.path.realpath('pytesseract_ocr.py'))+'/temp_images'

#returns the orientation of image
def getImageOrientation(image):
    try:
        orientation = str(pytesseract.image_to_osd(image)).split('\n')[1].split(':')[1]
        return orientation
    except pytesseract.pytesseract.TesseractError:  #Exception occurs on empty pages, return 0 orientation
        return 0
def reduceNoise(imageName, value):
    img = cv2.imread(imageName)
    dst = cv2.GaussianBlur(img, (value, value), 0)  # blur the images slightly to reduce noisy effects
    cv2.imwrite("./processed/"+imageName, dst)

def digitizeImage(imageName, value):
    print(value)
    # create pdf of image
    # makeSearchablePDF.converImageToPDF(path + imageName)
    reduceNoise(imageName, value)

    image = Image.open("./processed/"+imageName)
    image = image.convert("RGBA")

    orientation = getImageOrientation(image)
    rotated = image
    if (orientation != 0):
        rotated = image.rotate(360 - int(orientation))
    text = pytesseract.image_to_string(rotated, config='--psm 6')  # this config helps to read row by row
    return text

print(digitizeImage("image.png", 19))

在本地环境中,这将返回非常好的OCRed结果。但是,一旦将其泊坞窗化,它的输出将非常糟糕。

0 个答案:

没有答案