opencv.imshow将导致jupyter笔记本崩溃 [英] opencv.imshow will cause jupyter notebook crash

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

问题描述

我检查了Google或stackoverflow上的其他问题,他们谈论的是在脚本中运行cv2.imshow,但是我的代码在jupyter笔记本中运行.

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

python 3.5

opencv 3.1.0

opencv 3.1.0

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

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笔记本内核将死亡,我必须重新开始.

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.

这是我的错误图片:

Here is the pic of my error:

推荐答案

%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笔记本崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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