在之前的文章中,在TX2上利用GStreamer和OpenCV实现了板载相机/USB相机/IP摄像头的读取,这篇文章在之前的基础上,重点优化了读取网络相机视频的代码,并通过OpenCV将视频一帧一帧进行保存,具体代码如下
# coding=utf-8
import sys
import argparse
import cv2
import numpy as np
if __name__ == "__main__":
image_width = 1920
image_height = 1080
rtsp_latency = 200
uri = "rtsp://192.168.171.199:554/user=admin&password=&channel=1&stream=0.sdp?"
gst_str = ("rtspsrc location={} latency={} ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! videoconvert ! appsink sync=false").format(uri, rtsp_latency, image_width, image_height)
cap = cv2.VideoCapture(gst_