-3

I am making a python app i need openCV library here is my code:

# 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()

when I run the code I got this error:

[ 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)

I think may be it requires a codec driver but i don't know how to fix the error please help me friends

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

2 Answers2

2

following code resolved this issue for me: cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)

Basant Rawat
  • 201
  • 1
  • 3
1

try

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)