1

I am trying to get a realtime video input into opencv. My video input is coming from a ip camera on my localnetwork, that sends a rtsp video feed. What I want to make is a body tracker that uses the ip camera feed. Whit my usb hd720 Logitech webcam works it perfectly, but not whit the ip camera. The problem is that there is a lag, mostly of 8 seconds. I have already tried the most things and I could get it down to 3 seconds but this is still to long:

1: set buffer of cv2.videoCapture() to 1 and set the correct frames 2: multi threading of capturing the camera feed and my tracker program 3: tried a lot of different codes that supposed to work.

I know that the problem is in opencv that can't handle the rtsp feed. Now I am trying to get my camera feed trough GStreamer. Im hoping that there is a way that gstreamer converts the rtsp feed to something that opencv can handle faster.

import cv2
gst = 'rtspsrc location=rtsp://username:pasword@10.2.9.164:554/h264Preview_01_main ! ......... ! appsink'
cap = cv2.VideoCapture(gst,cv2.CAP_GSTREAMER)
while(cap.isOpened()):
  ret, frame = cap.read()
  if not ret:
    break
cv2.imshow('frame', frame)

if cv2.waitKey(400) & 0xFF == ord('q'):
  break

i hope somebody knows the correct gstreamer string

I could not find the correct string for gstreamer to convert rtsp signal to appsink

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
BramSanden
  • 11
  • 2

1 Answers1

1

You may try the following:

import cv2
gst = 'rtspsrc location=rtsp://username:pasword@10.2.9.164:554/h264Preview_01_main latency=300 ! decodebin ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1'

# Variant for NVIDIA decoder that may be selected by decodebin:
# gst = 'rtspsrc location=rtsp://username:pasword@10.2.9.164:554/h264Preview_01_main latency=300 ! decodebin ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1'

cap = cv2.VideoCapture(gst,cv2.CAP_GSTREAMER)
while(cap.isOpened()):
  ret, frame = cap.read()
  if not ret:
    break
  cv2.imshow('frame', frame)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cv2.destroyAllWindows()
cap.release()
SeB
  • 1,159
  • 6
  • 17