opencv.imshow 会导致 jupyter notebook 崩溃 [英] opencv.imshow will cause jupyter notebook crash

查看:56
本文介绍了opencv.imshow 会导致 jupyter notebook 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 google 或 stackoverflow 上查看了其他问题,他们正在谈论在脚本中运行 cv2.imshow,但我的代码在 jupyter notebook 中运行.

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

这是我的配置:

  1. ubuntu 16.4x64

  1. ubuntu 16.4x64

python 3.5

opencv 3.1.0

opencv 3.1.0

我启动了一个 jupyter notebook:这是我把它放在 notebook 中的代码:

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

当我执行这些代码时.图像将显示在弹出窗口中,但我无法通过单击右上角的 x 关闭此窗口,稍后,系统会提示我该窗口没有响应,它会给我 2 个选择:等待",退出".如果我点击等待,那么稍后它会显示相同的提示,如果我点击退出前",那么 jupyter notebook 内核会死掉,我必须重新开始.

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.

我google了一下,很多解决方案建议我应该添加这个代码

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

cv2.startWindowThread()

imshow 之前,但情况变得更糟,内核永远挂起!任何人都知道发生了什么.

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

这是我的错误图片:

推荐答案

%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()

这篇关于opencv.imshow 会导致 jupyter notebook 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆