1

I am a beginner in image processing, opencv, and python. I want to display an image using jupyter notebook on Mac and close the window but its not working. In addition, python.app stops working so I have to force quit it, causing my kernel to die, which I then have to restart as well. I am using python 2.7 for this and opencv 3.4.1

import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('messi5.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

it is partially not duplicate as it tries to seek answer for jupyter notebook.

  • My suggestion is to run code in python in terminal. You will not face any kind of problem – Lodi Jul 13 '18 at 17:12
  • Try to run `cv2.startWindowThread()` before `img = cv2.[...]` – Lodi Jul 13 '18 at 17:15
  • Or, maybe, in between `img = cv2.[...]` and `cv2.imshow[...]` – Lodi Jul 13 '18 at 17:16
  • [https://stackoverflow.com/questions/6116564/destroywind..](https://stackoverflow.com/questions/6116564/destroywindow-does-not-close-window-on-mac-using-python-and-opencv#15058451) it is outdated now. it would be helpful if you update it please –  Jul 13 '18 at 17:16
  • thats what I pointed out in my last comment.... I have seen it but it is 7 years old and code is not working. p.s. I can also see the LINKED category on my RHS –  Jul 13 '18 at 17:53
  • @ankiiiiiii try using `cv2.waitKey(1)` at the end. – Jeru Luke Jul 13 '18 at 17:53
  • @JeruLuke `cv2.waitKey(1)` has no effect in jupyter and in terminal it works without that too :) –  Jul 13 '18 at 18:51

1 Answers1

0

maybe its the copy of the mentioned question but I followed the first comment and got it solved by using terminal but someone need to find and tell why jupyter causes such problem.