Unable to display opencv image

Asked 2 years ago, Updated 2 years ago, 28 views

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'

python

2022-09-30 21:40

1 Answers

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.


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.