0
このコードでは、tesseract OCRのRGB画像をcv2、NumPy、PILなどのツールを使用して前処理しています。このコードをPython 2.7.13シェルで実行すると、次のエラーメッセージが表示されます。関数adaptiveThresholdのCV_8UC1(Error-215)
Traceback (most recent call last): File "C:\Automation\OCR\images\OCR_Preprocessing_ RGB.py", line 23, in <module> cv2.THRESH_BINARY,11,2) error: C:\build\master_winpack-bindings-win32-vc14-static\opencv\modules\imgproc\src\thresh.cpp:1446: error: (-215) src.type() == CV_8UC1 in function cv::adaptiveThreshold
エラーが発生したコードは次のとおりです。問題の可能性があると思われるコード行をマークしています。
import cv2
import numpy as np
from matplotlib import pyplot as plt
from cycler import cycler
from PIL import Image, ImageEnhance
# Loads the image then enhances it
image = Image.open('teleCapture.png')
contrast = ImageEnhance.Contrast(image)
img = contrast.enhance(2)
img = np.asarray(img)
r,g,b,a = cv2.split(img) // I know the issue is here, I have too many channels for an RGB image or I am merginf them wrong.
contrast = cv2.merge([b,g,r]) //"Contrast" was used as a src during Thresholding, is this what it should be?
# Adaptive Gaussian Thresholding //The problem may be within the thresholding, does this thresholding function only work using grayscale images?
th1 = cv2.adaptiveThreshold(contrast,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
# Otsu's thresholding
ret2,th2 = cv2.threshold(contrast,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(contrast,(5,5),0)
ret3,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# writes enhanced and thresholded img
cv2.imwrite('preprocessedTeleCapture.png', th2)
よろしくお願いします。@AndreySmorodovあなたは私に上記のコードを使用した例を教えていただけますか? – lizardwizard
ちょうどコードを修正すればうまくいくでしょう、私は何が間違っているのかを指摘しました。私はこれが何であるのか分からず、それが何をすべきか、しきい値を各チャンネルに適用するか、またはそれを灰色に変換して閾値に変換します。どこでも同じ過ちがあります。私はこのコードで何を意味したのか分かりません。 –
1つのチャネルでエラーが発生しました。トレースバック(最新の最後の呼び出し): ファイル "C:\ Automation \ OCR \ images \ OCR_Preprocessing_RGB.py"、行19、 コントラスト= cv2.merge([x]) TypeError:mvはnumpyの配列ではなく、スカラーの –
lizardwizard