如何解决Colab / Jupyter / Python:如何读取上传的文件
我熟悉Python,但是尝试在Google驱动器/可乐中使用它。我似乎无法使用下面的代码加载图像(该文件与代码/笔记本位于同一文件夹中)。有什么想法吗?
import cv2
file1 = 'image1.JPG'
image = cv2.imread(file1)
if(image):
print("File present")
else:
print("File not present")
解决方法
检查图像是否确实存在,一种方法是使用内置的IPython库
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
由于运行numpy数组的模棱两可,我在上面用一个有效的图像运行了您的代码,并得到了一个错误:
import cv2
file1 = 'file1.JPG'
image = cv2.imread(file1)
print(type(image))
if image.any():
print("File present")
else:
print("File not present")
# Returns "File present"
考虑这些建议,并使用绝对有效的url链接稍稍更改代码即可获得所需的输出:
public ref class LibTidy
{
public:
System::String^ __clrcall Test(System::String^ input);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。