我编译了这个程序,它从细胞图像中提取特征,并在 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 function something 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 example else: 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/