如何使用OpenCV Python在rtsp协议上从IP摄像机保存videstreem?

时间:2019-01-06 22:30:47

标签: python opencv rtsp

输出文件大小为6 kb,无法启动

如何保存文件?也许还有其他编解码器?我尝试了H264,X264,XVID等,但没有帮助。我从相机获得H264。

import cv2

detector = cv2.CascadeClassifier('D:\\python\\untitled\\haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture("rtsp://192.168.1.200:554/11")  
fourcc = cv2.VideoWriter_fourcc(*'MPEG')
out = cv2.VideoWriter(r'D:\python\untitled\output.avi', fourcc, 20.0, (640,480))

while (True):
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = detector.detectMultiScale(gray, 1.3, 5)
    out.write(img)

    for (x, y, w, h) in faces:
        # out.write(img)
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

    cv2.imshow('frame', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
out.release()
cv2.destroyAllWindows()

0 个答案:

没有答案