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