赞
踩
我正在尝试显示网络摄像头拍摄的图像。但是,存储捕获图像的变量是空的。此问题仅在使用网络摄像头时出现,而不是在播放mp4等视频时出现。这个问题是由Python版本引起的吗?我的OpenCV版本是3.4.3,Python版本是3.6.5。在import numpy as np
import cv2
from IPython import display
import matplotlib.pyplot as py
%matplotlib inline
def showVideo():
try:
print('카메라를 구동합니다.')
cap = cv2.VideoCapture(0)
except:
print('카메라 구동 실패')
return
print(cap.isOpened())
print(cap.read())
cap.set(3, 480)
cap.set(4, 320)
try:
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
if not ret:
# Release the Video Device if ret is false
cap.release()
# Message to be displayed after releasing the device
print ("Released Video Resource")
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Turn off the axis
py.axis('off')
# Title of the window
py.title("Input Stream")
# Display the frame
py.imshow(frame)
py.show()
# Display the frame until new frame is available
display.clear_output(wait=True)
except keyboardInterrupt:
# Release the Video Device
cap.release()
# Message to be displayed after releasing the device
print("Released Video Resource")
pass
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。