Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.imshow() is not working properly in PyCharm (MacOS)

Environment:

  • interpreter: Python 3.9.0
  • OS: macOS Big Sur

This simple code is running fine with no errors; however, no image is produced and nothing is displayed, and I'm forced to manually stop the code and interrupt it to exit, otherwise it just seems to run forever? This exact same code used to work fine on my windows laptop. Any clue? The code:

import cv2

CV_cat = cv2.imread('Cat.jpg')
cv2.imshow('displaymywindows', CV_cat)
cv2.waitKey(1500)
like image 664
Omar AlSuwaidi Avatar asked Mar 01 '23 21:03

Omar AlSuwaidi


2 Answers

import cv2

CV_cat = cv2.imread('Cat.jpg')
cv2.imshow('displaymywindows', CV_cat)
cv2.waitKey(0)   #wait for a keyboard input
cv2.destroyAllWindows()

try this code

like image 107
sourab maity Avatar answered Mar 05 '23 21:03

sourab maity


With Ubuntu 18.04 and Anaconda environment I was getting the error with Pycharm as

process finished with exit code 139 (interrupted by signal 11 sigsegv)

Solved it by pip install opencv-python-headless in addition to pip install opencv-python

like image 21
Sujith R Kumar Avatar answered Mar 05 '23 22:03

Sujith R Kumar