【发布时间】:2021-12-09 19:14:43
【问题描述】:
我正在尝试将使用 OpenCV 库的 CLAHE 方法应用于已拆分的绿色通道,但随后出现此错误:
cl = clahe.apply(multiBands[1])
TypeError: Expected cv::UMat for argument 'src'
我的代码:
# Example Python Program for contrast stretching
from PIL import Image
import cv2 as cv
# Method to process the green band of the image
def normalizeGreen(intensity):
iI = intensity
minI = 90
maxI = 225
minO = 0
maxO = 255
iO = (iI-minI)*(((maxO-minO)/(maxI-minI))+minO)
return iO
# Create an image object
imageObject = Image.open("input/IDRiD_02.jpg")
# Split the red, green and blue bands from the Image
multiBands = imageObject.split()
# create a CLAHE object (Arguments are optional)
clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
cl = clahe.apply(multiBands[1])
# Apply point operations that does contrast stretching on each color band
normalizedGreenBand = cl.point(normalizeGreen)
# Display the image before contrast stretching
imageObject.show()
# Display the image after contrast stretching
normalizedGreenBand.show()
【问题讨论】:
-
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
-
您将 PIL 图像传递给 OpenCV 函数。不支持。
-
OpenCV 的 python 绑定经常吐出这个消息。对于给定的参数,可以接受各种类型,但“UMat”是该参数列表中的 last 类型......它只报告该参数,而不是其他选项。
-
PIL 和 OpenCV 有不同的图像格式。您必须从一种格式转换为另一种格式。
-
@DanMašek 感谢您的回答,顺便问一下。在opencv中,有没有像poin()这样的函数?
标签: python numpy opencv computer-vision python-imaging-library