当前位置:   article > 正文

python opencv 拍照_在jupyter noteb中使用opencv显示网络摄像头中的图像

jupyter cv2 摄像头 image.empty

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/280362
推荐阅读
相关标签
  

闽ICP备14008679号