首页 > 解决方案 > 运行 python opencv 脚本时出现“选择超时”错误

问题描述

我正在尝试从 USB 3.0 网络摄像头捕获视频/图像馈送。每当我尝试运行此代码时,代码都会运行并捕获提要。但是,过了一会儿我得到“选择超时”。错误不会被异常捕获。有人可以帮我解决这个问题吗?

select timeout

OpenCV Error: Assertion failed (total() == 0 || data != __null) in Mat, file /home/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp, line 500
try:

    while True:
        ret, frame = cap.read()
        if ret != True:
            break
        if stat == None:
            stat = ret
            print('[INFO] ---- Reading video feed')
            continue
        frame = cv2.resize(frame , (int(320/2),int(240/2)))
        video.write(frame)
        if stat1 == None:
            stat1 = ret
            print('[INFO] ---- Video recording on process')
            continue
        c+=1
        print(c)
        key = cv2.waitKey(30) & 0xFF
        if key == 27:
            break
        elif c == 1200:
            break
except Exception as e:

        print(e)
        sys.exit()

我也试过编辑'uvcvideo'驱动参数

$ modprobe uvcvideo nodrop=1 timeout=6000

还有,启用模块跟踪,

$ sudo echo 0xffff > /sys/module/uvcvideo/parameters/trace

在“dmesg”图像上观察到这些错误

我遵循的链接: 在 Ubuntu 中选择超时错误 - Opencv

标签: pythonopencvlinux-kernelwebcamuvc

解决方案


推荐阅读