Ask Your Question
-1

Imshow doesn't work in Jupyter and PyCharm [closed]

asked 2020-07-02 08:54:00 -0500

Oregano Hauch gravatar image

updated 2020-07-02 09:11:45 -0500

Hello,

I want to use Imshow in Jupyter Notebook (PyCharm just for checking if it is a Jupyter specific problem, but I get the same result there).

When I type in

img1 = cv2.imread(r"savefig/plotXBIC_singlecell/01.png")
cv2.imshow("image",img1)
cv2.waitKey(0)
cv2.destroyAllWindows()

I get the error message:

OpenCV(4.2.0) /io/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

And when I do this:

gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

I get the error message:

OpenCV(4.2.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

EDIT: I checked with path.exists() if the path exists and yes, it does (both the relative and absolute one). And in both cases, with the same path (relative/absolute) I get a None when I type in print(cv2.imread(r"savefig/..../01.png))

Can you help me, please? :)

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by berak
close date 2020-07-02 13:31:27.537195

Comments

downvoted for: we have answered this question here like 5000 times before, you did no research at all

berak gravatar imageberak ( 2020-07-02 09:01:45 -0500 )edit

I did, but the path does exist. And I couldn't find anything about the contradiction between the True from path.exists() and the None from print(imread())..

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:07:09 -0500 )edit

Here is link jupyter

supra56 gravatar imagesupra56 ( 2020-07-02 09:34:29 -0500 )edit

I already read that article. It doesn't pertain to my problem. :/

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:52:09 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-07-02 08:58:18 -0500

berak gravatar image

updated 2020-07-02 09:06:15 -0500

your image was not loaded. (so your code fails in the next lines)

please make it a habit to check the output of imread() or similar io before trying to use the result

also, be careful with relative file path, if using weird ide's like jupyter or pycharm, it's usually not what you expect. when in doubt, try with an absolute path to your media

edit flag offensive delete link more

Comments

I checked that. path.exists gave me a True.

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:05:55 -0500 )edit

yea, but it's not relative to where your program started

berak gravatar imageberak ( 2020-07-02 09:07:30 -0500 )edit

print(imread) gave me a None, but the path exists. How can that be?

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:07:33 -0500 )edit

path.exists() is also relative to my cwd

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:07:59 -0500 )edit

I have the same results when I type in the absolute and relative path. I always get a True with path.exists() and a None with print(imread())

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:10:31 -0500 )edit

What happend if you remove r?

supra56 gravatar imagesupra56 ( 2020-07-02 09:18:26 -0500 )edit

Can you try this and put png in your currently folder?

img1 = cv2.imread("01.png")
supra56 gravatar imagesupra56 ( 2020-07-02 09:20:23 -0500 )edit

i have no idea about path.exists in your context . but if you can't open() it, you can't imread() it either.

berak gravatar imageberak ( 2020-07-02 09:41:37 -0500 )edit

Thanks. I will answer shortly.

Oregano Hauch gravatar imageOregano Hauch ( 2020-07-02 09:52:30 -0500 )edit

@berak. check this link cv2.imshow will you?

supra56 gravatar imagesupra56 ( 2020-07-02 09:54:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-07-02 08:53:07 -0500

Seen: 134 times

Last updated: Jul 02