Opencv does not works (Python 3) [closed]

asked 2020-09-13 09:19:24 -0500

Hi everybody! I`m trying to use opencv(opencv-contrib-python) + Python3.8 and my webcamera. And I have a warning:

"[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\videoio\src\cap_msmf.cpp (677) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(codec not found)" My code is:

import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, img = cap.read()
    cv2.imshow("camera", img)
    if cv2.waitKey(10) == 27:
        break
cap.release()
cv2.destroyAllWindows()

Tell me, please, what is the problem?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-14 12:05:38.379540

Comments

you can try cv2.VideoCapture(0, cv2.CAP_DSHOW)

sturkmen gravatar imagesturkmen ( 2020-09-13 09:32:09 -0500 )edit

Thank you very much! Now it works!

x-nikolas gravatar imagex-nikolas ( 2020-09-14 11:44:36 -0500 )edit