Python OpenCV捕获不工作MFVideoFormat_RGB24(未找到编解码器)遇到此问题,如何解决?

Python OpenCV捕获不工作MFVideoFormat_RGB24(未找到编解码器)遇到此问题,如何解决?,python,opencv,codec,Python,Opencv,Codec,我正在制作python应用程序我需要openCV库这是我的代码: # importing the required modules import cv2 import numpy as np # capturing from the first camera attached cap = cv2.VideoCapture(0) # will continue to capture until 'q' key is pressed while True: ret, frame = ca

我正在制作python应用程序我需要openCV库这是我的代码:

# importing the required modules
import cv2
import numpy as np

# capturing from the first camera attached
cap = cv2.VideoCapture(0)

# will continue to capture until 'q' key is pressed
while True:
    ret, frame = cap.read()
    cv2.imshow('frame', frame)

    # Program will terminate when 'q' key is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'): 
        break

# Releasing all the resources
cap.release()
cv2.destroyAllWindows()
运行代码时,出现以下错误:

[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wwma2wne\opencv\modules\videoio\src\cap_msmf.cpp (677) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(codec not found)
我想它可能需要一个编解码器驱动程序,但我不知道如何修复错误 请帮助我的朋友们

试试看


cap=cv2.VideoCapture0,cv2.cap_DSHOW以下代码为我解决了这个问题:cap=cv2.VideoCapture0,cv2.cap_DSHOW