【发布时间】:2021-01-17 00:09:38
【问题描述】:
我从 Jupyter Notebook 运行以下代码:
import cv2 as cv
contours, hierarchy = cv.findContours(im, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
cnt = contours[4]
cv.drawContours(im, contours, 2, (0, 230, 255), 6)
# Show the image with contours
cv.imshow('Contours', im)
cv.waitKey(0)
(im 是二值图像) 运行此程序后,Jupyter 内核会死掉。我应该改变什么?
【问题讨论】:
-
您是否通过逐个单元格分隔来调试代码?代码正在运行。如果您愿意,我可以解释并分享我的代码作为答案。
-
可能与waitKey(0)有关。在 Jupyter 中不起作用。
-
@GilPinsky 在 Jupyter 中应该使用什么? (我试过完全不用waitKey,还是不行)
-
@obart 你说的没用是什么意思?没显示?您可以尝试使用 matplotlib 显示结果: import matplotlib.pyplot as plt ,并使用 plt.imshow(im)。
-
@GilPinsky 是的,没有显示。我尝试使用 plt.imshow(im),但是显示的图像是原始图像,我想显示轮廓。谢谢!
标签: python opencv jupyter-notebook opencv-drawcontour