notebook: cv2.imshow(img) is crashing the kernel
As per title cv2.imshow(img) is crashing the server.
If we avoid cv2.waitForKey()
and cv2.closeAllWindows()
, and keep the windows open, the notebook will continue running.
Python version:
Python 3.5.6 |Anaconda custom (64-bit)| (default, Aug 26 2018, 16:05:27) [MSC v.1900 64 bit (AMD64)]
Kernel about:
Python 3.5.5 |Anaconda, Inc.| (default, Mar 9 2018, 12:39:44) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
To reproduce: (coming)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (1 by maintainers)
You can use this solution if you’re using google colab:
from google.colab.patches import cv2_imshow
cv2_imshow(img)
It works fine!You can also consider using
matplotlib
rather thanIPython.display
, although, I would not recommend to mix the two.Copying the mentioned function
cv2_imshow
fromcolabtools
and using it locally worked well for me. It displays the image inline.@Oshana just say -
cv2_imshow(cv2.resize(image_np, (800, 600)))
cv2_imshow only takes one input parameter, https://github.com/googlecolab/colabtools/blob/8708337447efdef2732cca9764ede400da6c051f/google/colab/patches/__init__.py#L14hi guys, here is the solution of the problem.
If you are using a 64-bit machine, you will have to modify
k = cv2.waitKey(0)
line as follows :k = cv2.waitKey(0) & 0xFF
The full solution is like this:
If you have this issue, check if the numpy array is of type float, if so then multiply the array by 255.
https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=imshow#imshow
This is just showing some black blank image.