简体   繁体   中英

Issue in running a function that returns the frames captured by webcam using opencv

I already wrote a code that can display the frames captured by webcam, but i want to write a function with can do the same, the code i wrote is below

import cv2

def cam2frame():

cap = cv2.VideoCapture(0)   

while(True):

    ret,frames = cap.read()
    gray = cv2.cvtColor(frames,cv2.COLOR_BGR2GRAY)
    cv2.imshow('frames',gray)
    return gray
    if cv2.waitKey(1) & 0xFF == ord('q'):

        break
cap.release()
cv2.destroyAllWindows()

cam2frame()

I am getting this error:

[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback

I want the function to return the frame captured and I also want to use the function in a different.py file

Use this setx OPENCV_VIDEOIO_PRIORITY_MSMF 0 before running your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM