TypeError:' NoneType'对象在cv2.Normalize中是不可取消的

时间:2018-03-24 06:19:57

标签: python linux opencv machine-learning raspberry-pi

我编译了这个程序,它从细胞图像中提取特征,并使用python-3.5上的randomforestclassifier来判断它是否是癌症。我在Windows 8.1上完成了它的工作。但它没有在我的覆盆子pi上工作,它有锉刀拉伸操作系统。这是显示错误的代码。

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

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

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