Python CV2:[ WARN:0]`anonymous-namespace‘SourceReaderCB~SourceReaderCB terminating async callback

一、出问题的代码

import numpy as np
import cv2

cap = cv2.VideoCapture(0)  # 摄像头编号。

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')  # 注意编码器
out = cv2.VideoWriter('output3.avi', fourcc, 20.0, (640, 480))

while cap.isOpened():
    ret, frame = cap.read()
    if ret:
        # 根据y轴对称
        frame = cv2.flip(frame, 1)
        # write the flipped frame
        out.write(frame)
        cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

二、解决办法

解决办法一:

将第三行 cap = cv2.VideoCapture(0)改为

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

解决办法二:

windows 下:在命令行中输入:

setx OPENCV_VIDEOIO_PRIORITY_MSMF 0 

三、参考

  • [CV2: " WARN:0] terminating async callback" when attempting to take a picture

  • https://github.com/opencv/opencv-python/issues/198

你可能感兴趣的:(OpenCV/Python,python,opencv)