0

I'm getting a warning while trying to run the following code. I have added the cv.destroyAllWindows() function as well. The warning is still showing.

import cv2 as cv
import datetime

cap = cv.VideoCapture(0)
cap.set(3,1280)
cap.set(4,720)

while(cap.isOpened()):
    ret, frame = cap.read()

    if ret == True:
        text = "Width: "+str(cap.get(3))+" Height: "+str(cap.get(4))
        datet = str(datetime.datetime.now())
        frame = cv.putText(frame, datet, (10, 50), cv.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 255), 2, cv.LINE_AA)
        frame = cv.circle(frame, (640, 360), 200, (0, 255, 255), 2, cv.LINE_AA)
        cv.imshow("frame", frame)

        if cv.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
cv.destroyAllWindows()
Giri Kishore
  • 87
  • 2
  • 7

2 Answers2

6

this question is a duplicate of this one

using cap = cv.VideoCapture(0, cv2.CAP_DSHOW) fixed it for me

nullcline
  • 342
  • 1
  • 15
0

For fellow googlers, for whom the accepted answer is not working and is getting an error like this:

anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

The fix is downgrading the opencv version to 3.4.2.16

Do:

pip install opencv-python==3.4.2.16 
Manu S Pillai
  • 899
  • 8
  • 13