【问题标题】:In opencv imshow() function does not open the new window and display the image in jupyter notebook在 opencv imshow() 函数中不会打开新窗口并在 jupyter notebook 中显示图像
【发布时间】:2020-03-29 09:28:30
【问题描述】:
    import cv2
    cap = cv2.VideoCapture(0)
    status , photo = cap.read()
    cv2.imwrite('Surendar.png',photo)
    cap.release()  
    cv2.imshow('image', photo) 
    cv2.waitKey(5000) 
    cv2.destroyAllWindows()

我在我的 jupyter 笔记本中解释了这段代码。它只是符合但不显示图片的新窗口

【问题讨论】:

  • 我认为 jupyter 服务器没有在本地机器上运行?

标签: python-3.x opencv


【解决方案1】:

尝试将cv2.waitKey(5000) 更改为cv2.waitKey(0),这样窗口就会一直保持到用户关闭它为止。看起来窗口在销毁窗口之前等待了 5000 毫秒。

编辑

不要使用 cv2 来显示图像,而是尝试使用 matplot

import cv2
from matplotlib import pyplot as plt

cap = cv2.VideoCapture(0)
status , photo = cap.read()
cv2.imwrite('Surendar.png',photo)
cap.release()  
plt.imshow(photo)
plt.show()

【讨论】:

  • 即使我把它改成cv2.waitKey(0)它仍然打开新窗口来显示图像
猜你喜欢
  • 2021-03-13
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
  • 2022-11-28
  • 2017-11-30
  • 1970-01-01
  • 2020-04-23
相关资源
最近更新 更多