[英]cv2 imshow not displaying image and locking up the kernel
I run my code which is locking up my kernel.我运行我的代码,它锁定了我的 kernel。 I'm in a jupyter notebook using anaconda.我在使用 anaconda 的 jupyter 笔记本中。 The kernel indicator (Python 3 (ipykernel)) circle is solid and stays that way. kernel 指标(Python 3 (ipykernel))圆圈是实心的并保持这种状态。 I uninstalled and reinstalled opencv-python with pip.我用 pip 卸载并重新安装了 opencv-python。 I'm not sure what is(or isn't)going on.我不确定发生了什么(或没有发生)。 My file is in the same directory as my JNB (so, no file not found in directory issue)我的文件与我的 JNB 位于同一目录中(因此,在目录问题中找不到文件)
Here is my code:这是我的代码:
import cv2
img = cv2.imread('galaxy.jpg', cv2.IMREAD_GRAYSCALE)
print(type(img))
print(img)
print(img.shape) # (1485, 990)
print(img.ndim) # 2 because grayscale
cv2.imshow('Galaxy', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is the output I do get:这是我得到的 output:
<class 'numpy.ndarray'>
[[14 18 14 ... 20 15 16]
[12 16 12 ... 20 15 17]
[12 13 16 ... 14 24 21]
...
[ 0 0 0 ... 5 8 14]
[ 0 0 0 ... 2 3 9]
[ 1 1 1 ... 1 1 3]]
(1485, 990)
2
But no display of the image?但是没有显示图像? Can anyone tell me what I'm doing wrong?谁能告诉我我做错了什么?
This worked on jupyter notebook:这适用于 jupyter 笔记本:
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("galaxy.jpg")
plt.imshow(img)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.