Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2.imshow() crashes Kernel

Tags:

I am running OpenCV through Jupyter Notebooks and whenever I try to run cv2.imshow() the kernel crashes, no error message or helpful hint - just a plain

The Kernel appears to have died. It will restart automatically.

Here is the code I am running...

import cv2 
input = cv2.imread('images/input.jpg')
cv2.imshow('Hello World', input)
cv2.waitKey(0)
cv2.destroyAllWindows()

The code works (albeit differently) when I run the below...

%matplotlib inline
from matplotlib import pyplot as plt
import cv2
image = cv2.imread('images/input.jpg')
plt.imshow(image)
plt.show()

FYI I am using a completely unaltered copy of BitFusion on AWS.

https://aws.amazon.com/marketplace/pp/B01EYKBEQ0?ref=cns_srchrow

Any idea what could be going wrong?

like image 961
Mike de H Avatar asked May 12 '17 17:05

Mike de H


People also ask

Can we use cv2 Imshow in Jupyter?

The cv2. imshow function in OpenCV malfunctions in a client/server environment such as Jupyter. However, Matplotlib does not have this problem.

What is cv2 Imshow ()?

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


1 Answers

I can't explain the behavior of your code right now but you can use the below code to achieve the above behavior.

%matplotlib inline
from matplotlib import pyplot as plt
import cv2
image = cv2.imread('images/input.jpg')
plt.imshow(image)
plt.show()
like image 157
Puneet Jindal Avatar answered Oct 26 '22 06:10

Puneet Jindal