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

标签 python linux opencv machine-learning raspberry-pi

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

相关文章:

java - OpenCV 如何检测网络摄像头并比较本地文件以匹配人脸

python - 在 Python 中间歇性地跳行

linux - 如何使用管道从文件中输出 id-address 并登录?

python - 使用 python 正则表达式在另一个模式中编译模式

python - 通过脚本结果进行远程 NFS 配置

c - 如何在父进程重新启动时使子进程死亡

c++ - CodeLite opencv路径

opencv - 计算cvInRangeS中的最小值和最大值

python - 获取 Linux 服务器中文件夹的大小

python - 如何在c级调试python?