imstraight
2020-05-03 16:00
采纳率: 100%
浏览 1.6k

python的opencv打开两个摄像头失败

今天在搞双目的时候碰到的,之前在笔记本上可以运行的,换了台式出问题了。应该是**cv2.VideoCapture**就出问题了,网上翻了半天,不加上微软专属的**cv2.CAP_DSHOW**会出现

[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1113) SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -1072875772
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1125) SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:1] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1159) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -1072875772

加上了就没有这个问题,但是第二个摄像头依然不能使用,读取帧返回false,报错

cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

求解决!!
附部分代码:

import cv2
capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
capture_usb = cv2.VideoCapture(1, cv2.CAP_DSHOW)
# 持续读取摄像头数据
while True:
    read_code, frame = capture.read()
    read_code2, frame2 = capture_usb.read()
    cv2.imshow("1", frame)
    cv2.imshow("2", frame2)
    if cv2.waitKey(1) == ord('q'):
        break
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dabocaiqq 2020-05-04 15:04
    已采纳
    已采纳该答案
    打赏 评论
  • 我是龙龙龙 2021-09-23 13:32

    兄弟,问题解决没有啊,我也遇到和你一样的问题了

    打赏 评论

相关推荐 更多相似问题