繁体   English   中英

函数AdaptiveThreshold中的CV_8UC1(Error-215)

[英]CV_8UC1 (Error-215) in function adaptiveThreshold

在此代码中,我们正在使用cv2,NumPy和PIL等工具对Tesseract OCR的RGB图像进行预处理。 在Python 2.7.13 Shell中执行此代码后,我收到以下错误消息。

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)

阈值方法需要1个通道图像作为输入,而您提供3个通道,这就是错误消息中显示的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM