gpt4 book ai didi

python - 在python-opencv中打印读取图像的像素值时出现错误,TypeError: 'NoneType'对象没有属性 '__getitem__'

转载 作者:行者123 更新时间:2023-12-02 17:44:10 25 4
gpt4 key购买 nike

我刚安装了opencv,并通过键入以下命令检查其是否已正确安装:

pkg-config --modversion opencv

在命令终端。

我开始使用pything-opencv读取和显示图像,但是当我运行代码时,它将引发错误:
TypeError: 'NoneType' object has no attribute '__getitem__'

我的代码非常少,但没有出现错误。

我正在运行的代码是:
import cv2
import numpy as np
from matplotlib import pyplot as plt
import argparse

img = cv2.imread('messi5.jpg')
print(img)
print("end of file")

它给出了输出:
None
end of file

当我再这样写两行时:
px = img[100,100]
print(px)

然后抛出错误:
追溯(最近一次通话):
文件“testing_opencv_python.py”,第23行,在
px = img [100,100]
TypeError:“NoneType”对象没有属性“ getitem

相同的代码可以在其他系统上完美运行。

如果您能指出错误,我将不胜感激。

我基本上想安装caffe,但是当我这样做时,我遇到了错误,并且好像它依赖于opencv,多数民众赞成在乳清我已经安装了opencv。

感谢致敬。

最佳答案

返回的图像是None(在打印时可以看到它),这会导致另一条错误。

这很可能是由于指定了错误的图像路径('messi5.jpg')。在文档here中,它指出:

Warning Even if the image path is wrong, it won’t throw any error, but print img will give you None



提供正确的“messi5.jpg”路径,或将图像复制到当前目录(在其中执行python脚本)。

关于python - 在python-opencv中打印读取图像的像素值时出现错误,TypeError: 'NoneType'对象没有属性 '__getitem__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975230/

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