How do I fix issue with no window opening with cv2.imshow?

asked 2020-03-12 17:02:08 -0500

updated 2020-03-13 03:53:10 -0500

supra56 gravatar image

I successfully use cv2.imread to read an image. I can display in the console using matplotlib.imshow. When I use cv2.imshow, nothing happens, no errors, no window opens. Script ends normally, but no image. I tried using different integers with cv2.waitKey() and leaving it empty, but no luck. Works great on Windows, but not on my Mac.

Using Python 2.7, Spyder 3.3.6, openCV 4.2.0.

import cv2
import numpy as np
import matplotlib.pyplot as plt
img =cv2.imread('/Users/Paul/Documents/Photos/F15.jpg',cv2.IMREAD_GRAYSCALE)
edit retag flag offensive close merge delete


You must check image after read :

if img is None:
     print("Check file path")

Python 2 is dead :

LBerger gravatar imageLBerger ( 2020-03-13 01:56:34 -0500 )edit

The path is fine. As I said, the image displays properly using matplotlib.

The code is working on Python 2.7 and 3.7 on my personal computers. This appears to be Mac related.

PaulSpon gravatar imagePaulSpon ( 2020-03-13 12:19:45 -0500 )edit

Installed Python 3.7. This did not resolve my issue.

PaulSpon gravatar imagePaulSpon ( 2020-03-13 15:50:25 -0500 )edit

Ok it's mac so read this and may be you will find something to solve your problem

LBerger gravatar imageLBerger ( 2020-03-13 16:22:53 -0500 )edit

I read through the items and did additional searches. Nothing is crashing and there were no errors, so the threads didn't help.

Now getting a new error which I will research on my own. Several identical lines of:

[IPKernelApp] WARNING | No such comm: 7a6fd824656d11ea9fc0a45e60dd0c91

PaulSpon gravatar imagePaulSpon ( 2020-03-13 17:44:00 -0500 )edit