gpt4 book ai didi

python - TypeError : 'NoneType' object is unsubscriptable in cv2. 归一化

转载 作者:太空宇宙 更新时间:2023-11-04 12:09:31 25 4
gpt4 key购买 nike

我编译了这个程序,它从细胞图像中提取特征,并在 python-3.5 上使用 randomforestclassifier 判断它是否癌变。我是在 Windows 8.1 上制作的,它运行良好。但它不适用于我的树莓派,它有 raspbian stretch 操作系统。这是显示错误的代码。

def colorRatioMean(rgbImage):     
R = cv2.normalize(rgbImage[:,:,0].astype('double'), None, 0, 255,
cv2.NORM_MINMAX)
G = cv2.normalize(rgbImage[:,:,1].astype('double'), None, 0, 255,
cv2.NORM_MINMAX)
B = cv2.normalize(rgbImage[:,:,2].astype('double'), None, 0, 255,
cv2.NORM_MINMAX)

上面显示的代码是我的类中提取特征的部分。

我收到以下错误:

Traceback (most recent call last):
File "/home/pi/Desktop/Cancer_Detector/image.py", line 117, in <module>
r, g, b = features.colorRatioMean(image)
File "/home/pi/Desktop/Cancer_Detector/image.py", line 24, in colorRatioMean
R = cv2.normalize(rgbImage[:,:,0].astype('double'), 0, 255,
cv2.NORM_MINMAX)
TypeError: 'NoneType' object is not subscriptable

请帮我解决这个问题。

最佳答案

The image you are passing to function is a null image. To see the type of a null image:rgbImage = cv2.imread("some_non_existing_image.jpg")print ("Image type: ",type(rgbImage))the result will be:   'Image type: ', type 'NoneType'To resolve the problem test the image type before passaing it to the functionsomething like this where the function is beeing called:if rgbImage is None:  #  # do not pass it to function, perhaps by pass  #  print ("Null imagem")  pass # Only for exampleelse:  colorRatioMean(rgbImage)See: The "'NoneType' object is not subscriptable" is because there is nothing in it

关于python - TypeError : 'NoneType' object is unsubscriptable in cv2. 归一化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49461887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com