Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv.imshow will cause jupyter notebook crash

I check other question on google or stackoverflow, they are talking about run cv2.imshow in script, but my code run in jupyter notebook.

Here is my configuration:

  1. ubuntu 16.4x64

  2. python 3.5

  3. opencv 3.1.0

I start a jupyter notebook: here is the code I put it notebook:

%pylab notebook import cv2  cvim2disp = cv2.imread('data/home.jpg') cv2.imshow('HelloWorld', cvim2disp) cv2.waitKey() #image will not show until this is called cv2.destroyWindow('HelloWorld') #make sure window closes cleanly 

When I execute these code. image will show in a pop up window, but I can not close this window by clicking the x on the top right corner, and a moment later, system will prompt me that the window is not responding, it will give me 2 choices: "wait" , "fore quit". if I hit wait, then It will show the same prompt later, If I hit 'fore quit', then the jupyter notebook kernel die and I have to start over.

I google around, many solution suggest that I should add this code

cv2.startWindowThread() 

before imshow, but situation get worse, the kernel hang forever!. anybody have some idea what's going on.

Here is the pic of my error: enter image description here

like image 278
scott huang Avatar asked Sep 15 '17 09:09

scott huang


People also ask

Why is my Jupyter Notebook crashing?

Check which version of pyzmq is installed. If Jupyter Notebook and the kernel are in different conda envs, check both and make sure they are on the same version and build. Try upgrading or downgrading to different versions. According to Anaconda issue 8932, there are problems with pyzmq on Windows.

Does opencv work in Jupyter Notebook?

Type the command “pip install opencv-python” to install python lib You should see 'Successfully installed' to finish installing opencv-python. 7. Use Jupyter notebook to run python code Open the Windows Start menu in your Desktop, click “Anaconda3 (64-bit)”, and then click “Jupyter Notebook(anaconda3)”.

What does CV Imshow do?

cv2. imshow() method is used to display an image in a window. The window automatically fits to the image size.


1 Answers

%matplotlib inline #The line above is necesary to show Matplotlib's plots inside a Jupyter Notebook  import cv2 from matplotlib import pyplot as plt  #Import image image = cv2.imread("input_path")  #Show the image with matplotlib plt.imshow(image) plt.show() 
like image 133
Ritu dhoot Avatar answered Sep 29 '22 21:09

Ritu dhoot