Есть ли проблемы с openCV при докеризации? - PullRequest
0 голосов
/ 10 мая 2019

Я использую openCV в своем приложении OCR (оптическое распознавание символов), чтобы применить GaussianBlur с ядром (19, 19) в качестве метода предварительной обработки.OCR отлично работает в локальной среде.Но терпит неудачу, как только он dockerized.

Ядро с (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,Но как только он докеризован, он дает очень плохой результат.

...