我正在尝试显示网络摄像头拍摄的图像。但是,存储捕获图像的变量是空的。此问题仅在使用网络摄像头时出现,而不是在播放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

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐