I'm a beginner in programming.
Starting python3 on Jupiter notebook
I want to display the sample.jpg saved on my desktop inline in jupyter notebook, but I get an error.
I think path is a problem, but I don't know where the path is and how to pass it, so I searched it, but I can't understand it.Please give me some advice.
program
%matplotlib inline
import matplotlib.pyplot asplt
import cv2
img=cv2.imread("sample.jpg")
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.show()
error
error Traceback (most recent call last)
<ipython-input-13-98760eafe379>in<module>
3 import cv2
4 img=cv2.imread("prius.jpg")
---->5plt.imshow (cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
6plt.show()
error: OpenCV(4.0.0)/Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:181:error:(-215: Assertion failed)!_src.empty() in function 'cvtColor'
If sample.jpg
is in the same path as the Notebook you are editing now, you should be able to view it with this source code.
%pwd
can print the current working directory, so make sure it matches your expectations.
© 2025 OneMinuteCode. All rights reserved.