小编김진우*_*김진우的帖子

在 jupyter notebook 中使用 opencv 显示来自网络摄像头的图像

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

python opencv python-3.x

5
推荐指数
0
解决办法
4091
查看次数

标签 统计

opencv ×1

python ×1

python-3.x ×1