简体   繁体   English

尝试在Jupyter Notebook中显示本地图像时出现语法错误

[英]Syntax error when trying to display a local image in jupyter notebook

I am trying to display an image in my notebook such as, 我正在尝试在笔记本中显示图像,例如,

![title](img/x.png)

When I Change cell type to markdown it works but displays this 当我将单元格类型更改为降价时,它可以正常显示

在此处输入图片说明

Here is some diagnostics you can make using Python itself 这是您可以使用Python本身进行的一些诊断

import os
filename = 'img/x.png'
print(os.path.abspath(filename))

Does this command print the expected path? 此命令是否打印预期路径? If not, fix filename accordingly. 如果不是,请相应地修复文件名。

print(os.path.exists(filename))

Is this "True"? 这是真的”? If not, check that the file exists. 如果不存在,请检查文件是否存在。

For the following test you need OpenCV. 对于以下测试,您需要OpenCV。 If you don't have it, you need to install opencv-python , eg using pip install opencv-python . 如果没有,则需要安装opencv-python ,例如,使用pip install opencv-python

import cv2
im = cv2.imread(filename)
print(im.shape)

This should print a tuple with elements image height, image width and number of channels (for a color image). 这将打印一个元组,其中包含元素图像高度,图像宽度和通道数(对于彩色图像)。 If it doesn't, the image is most probably corrupted. 如果没有,则图像很可能已损坏。

You can also display the image using matplotlib: 您还可以使用matplotlib显示图像:

import matplotlib.pyplot as plt
plt.figure()
plt.imshow(im)
plt.show()

If you see wrong colors, probably matplotlib displays it uses a wrong palette or wrong channel order (RGB instead of BGR ets.) Take a look at plt.imshow help to find, how to fix it. 如果您看到错误的颜色,则可能是matplotlib显示它使用了错误的调色板或错误的通道顺序(RGB而不是BGR plt.imshow )。请查看plt.imshow帮助以查找如何修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试启动 Jupyter 笔记本时出现 DLL 错误 - DLL Error when trying to launch Jupyter notebook 尝试在 jupyter notebook 中拆分数据时出错 - Error when trying to split the data in jupyter notebook 在Jupyter笔记本电脑上显示错误 - Display error on Jupyter notebook 尝试将 zip 文件导入 jupyter notebook 和语法错误 - Trying to import zip file into jupyter notebook and syntax error jupyter notebook 中 sqlite 的语法错误 - syntax error on sqlite in jupyter notebook 尝试运行 next(iter(train_data_loader)) 时遇到 Broken Pipe 错误。 我在本地 jupyter notebook 中运行代码 - Facing Broken Pipe error when trying to run the next(iter(train_data_loader)). I'm running the code in local jupyter notebook 尝试在 Colab 中拟合模型时出错,但在 Jupyter 笔记本中工作正常 - Error when trying to fit the model in Colab but works fine in Jupyter notebook 尝试运行我的 Jupyter Notebook 时出现错误 13 - Error 13 When trying to run my Jupyter Notebook 尝试在 jupyter notebook 上运行 sql 命令时出错 - Error when Trying to run an sql command on jupyter notebook 尝试启动 Jupyter Notebook (Python) 时出现运行时错误 - Runtime Error when trying to launch Jupyter Notebook (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM