在opencv imshow()函数中,不会打开新窗口并使用anaconda在jupter笔记本中显示图像

问题描述 投票:0回答:1

    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笔记本中解释了此代码。它只是合规,但不显示图片的新窗口

python-3.x opencv machine-learning
1个回答
0
投票

尝试将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()
© www.soinside.com 2019 - 2024. All rights reserved.